📄 jfedit.pas
字号:
unit JFEdit;
interface
uses
SysUtils, Classes, Controls, StdCtrls, Mask, Buttons, Messages,
Windows, JFCommon, Graphics, Adodb, Forms, Math, MaskUtils, DB,
StrUtils, Dialogs, ExtCtrls, DBClient, RzEdit, JFMessage;
type
TJFEdtBtn = class(TWinControl)
private
FButton: TSpeedButton;
procedure WMSize(var MSG: TMessage); Message WM_Size;
protected
procedure ResizeButton; virtual;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Button: TSpeedButton read FButton;
end;
TJFEdit = class;
TEdtSearchFieldItem = class(TCollectionItem)
private
FFieldName: string;
FFieldType: TJFSearchFieldType;
FOperation: string;
FFullBlur: Boolean;
procedure SetFieldName(const Value: string);
procedure SetFieldType(const Value: TJFSearchFieldType);
procedure SetOperation(const Value: string);
procedure SetFullBlur(const Value: Boolean);
protected
public
constructor Create(Collection: TCollection); overload; override;
procedure Assign(Source: TPersistent); override;
published
property FieldName: string read FFieldName write SetFieldName;
property FieldType: TJFSearchFieldType read FFieldType write SetFieldType;
property Operation: string read FOperation write SetOperation;
property FullBlur : Boolean read FFullBlur write SetFullBlur; //完全模糊
end;
TEdtSearchFieldClass = class of TEdtSearchFieldItem;
TEdtSearchFields = class(TCollection)
private
FOwner: TPersistent;
function GetSearchField(Index: Integer): TEdtSearchFieldItem;
procedure SetSearchField(Index: Integer;
const Value: TEdtSearchFieldItem);
protected
function GetOwner: TPersistent; override;
public
constructor Create(AOwner: TPersistent;EdtSearchFieldClass: TEdtSearchFieldClass);
procedure Assign(Source: TPersistent); override;
function Add: TEdtSearchFieldItem;
property Items[Index: Integer]: TEdtSearchFieldItem read GetSearchField write SetSearchField; default;
published
end;
TEdtDispFieldItem = class(TCollectionItem)
private
FFieldName: string;
FDispWidth: Integer;
FAlignment: TAlignment;
FColumnTitle: string;
procedure SetFieldName(const Value: string);
procedure SetAlignment(const Value: TAlignment);
procedure SetDispWidth(const Value: Integer);
procedure SetColumnTitle(const Value: string);
protected
public
constructor Create(Collection: TCollection); override;
procedure Assign(Source: TPersistent); override;
published
property FieldName: string read FFieldName write SetFieldName;
property DispWidth: Integer read FDispWidth write SetDispWidth;
property Alignment: TAlignment read FAlignment write SetAlignment;
property ColumnTitle: string read FColumnTitle write SetColumnTitle;
end;
TEdtDispFieldClass = class of TEdtDispFieldItem;
TEdtDispFields = class(TCollection)
private
FOwner: TPersistent;
function GetDispField(Index: Integer): TEdtDispFieldItem;
procedure SetDispField(Index: Integer;
const Value: TEdtDispFieldItem);
protected
function GetOwner: TPersistent; override;
public
procedure Assign(Source: TPersistent); override;
constructor Create(AOwner: TPersistent; EdtDispFieldClass: TEdtDispFieldClass);
function Add: TEdtDispFieldItem;
property Items[Index: Integer]: TEdtDispFieldItem read GetDispField write SetDispField; default;
published
end;
TEdtExecParamitem = class(TCollectionItem)
private
FValue: Variant;
procedure SetValue(const Value: Variant);
protected
public
constructor Create(Collection: TCollection); override;
procedure Assign(Source: TPersistent); override;
published
property Value: Variant read FValue write SetValue;
end;
TEdtExecParamClass = class of TEdtExecParamitem;
TEdtExecParams = class(TCollection)
private
FOwner: TPersistent;
function GetExecParam(Index: Integer): TEdtExecParamitem;
procedure SetExecParam(Index: Integer;
const Value: TEdtExecParamitem);
protected
function GetOwner: TPersistent; override;
public
procedure Assign(Source: TPersistent); override;
constructor Create(AOwner: TPersistent; EdtExecParamClass: TEdtExecParamClass);
function Add: TEdtExecParamitem;
property Items[Index: Integer]: TEdtExecParamitem read GetExecParam write SetExecParam; default;
published
end;
TEdtBeforeShowSelect = procedure(var Allow: Boolean) of object;
TJFEditThread = class(TThread)
private
FJFEdit: TJFEdit;
protected
procedure Execute; override;
procedure InputKeys;
public
constructor Create(JFEdit:TJFEdit); overload;
end;
TJFEdit = class(TRzCustomEdit)
private
FTimer : TJFEditThread;
FJFEdtBtn : TJFEdtBtn;
FJFAlignment: TLeftRight;
FJFEditKind: TJFButtonKind;
FJFSearchFields: TEdtSearchFields;
FJFDispFields: TEdtDispFields;
FOnButtonClick: TNotifyEvent;
FJFSQLText: String;
FJFRemoteServer: TCustomRemoteServer;
FJFExecParams: TEdtExecParams;
FBeforeShowSelect: TEdtBeforeShowSelect;
FJFNumericValue: Extended;
FJFDateValue: TDateTime;
FJFSelectResult: TJFRecList;
FOnSelectReturn: TNotifyEvent;
FJFFilterChars: string;
FJFFocusMove: Boolean;
FJFDecimalDigits: Integer;
FJFMinNumeric: Extended;
FJFMaxNumeric: Extended;
FJFNumericLimit: Boolean;
FJFInputChars: string;
FJFMsgClear: Boolean;
FJFMultiSelect: Boolean;
FJFDispFieldName: string;
FJFBackspaceClear: Boolean;
FJFListRowCount: Integer;
FJFDispSeparator: string;
FJFDDTItemID: string;
FJFDDTParentID: string;
FJFDropDownList: TJFRecList;
FJFTimeVisible: Boolean;
FJFSecVisible: Boolean;
FInputKeys : string;
FJFDDNumSelect: Boolean;
FJFLimitSpace: Boolean;
FJFSRFocusMove: Boolean;
FJFEnterToSearch: Boolean;
FJFPacketRecords: Integer;
FJFClearDefIndex: Integer;
FJFSearchUseLocate: Boolean;
procedure SetJFAlignment(const Value: TLeftRight);
procedure SetJFEditKind(const Value: TJFButtonKind);
function GetButtonVisible: Boolean;
procedure SetButtonVisible(const Value: Boolean);
procedure WMSize( var Msg: TWMSize ); message wm_Size;
procedure CMEnter( var Msg: TCMEnter ); message cm_Enter;
procedure CMExit( var Msg: TCMExit ); message cm_Exit;
procedure WMPaste( var Msg: TWMPaste ); message wm_Paste;
procedure WMCut( var Msg: TWMCut ); message wm_Cut;
procedure CMEnabledChanged( var Msg: TMessage ); message cm_EnabledChanged;
procedure CMFontChanged( var Msg: TMessage ); message cm_FontChanged;
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
procedure WMPAINT(var Message: TMessage); message WM_PAINT;
procedure CMCtl3DChanged(var Message: TMessage); message CM_CTL3DCHANGED;
procedure SetButtonFlat(const Value: Boolean);
function GetButtonFlat: Boolean;
procedure SetJFSearchFields(const Value: TEdtSearchFields);
procedure SetJFDispFields(const Value: TEdtDispFields);
procedure SetOnButtonClick(const Value: TNotifyEvent);
procedure SetJFSQLText(const Value: String);
procedure SetJFRemoteServer(const Value: TCustomRemoteServer);
procedure SetJFExecParams(const Value: TEdtExecParams);
procedure SetBeforeShowSelect(const Value: TEdtBeforeShowSelect);
procedure SetJFDateValue(const Value: TDateTime);
procedure SetJFNumericValue(const Value: Extended);
procedure SetOnSelectReturn(const Value: TNotifyEvent);
procedure SelectReturn(var MSG: TMessage); message JF_MSG_RETURN_SELECT_RESULT;
procedure SetJFFilterChars(const Value: string);
procedure SetJFFocusMove(const Value: Boolean);
procedure SetJFDecimalDigits(const Value: Integer);
procedure SetJFMaxNumeric(const Value: Extended);
procedure SetJFMinNumeric(const Value: Extended);
procedure SetJFNumericLimit(const Value: Boolean);
function GetText: string;
procedure SetText(const Value: string);
procedure SetJFInputChars(const Value: string);
function GetEditMask: TEditMask;
procedure SetEditMask(const Value: TEditMask);
procedure SetJFMsgClear(const Value: Boolean);
procedure MSGClear(var MSG: TMessage); message JF_MSG_CLEAR;
procedure SetJFMultiSelect(const Value: Boolean);
procedure SetJFDispFieldName(const Value: string);
procedure SetJFBackspaceClear(const Value: Boolean);
procedure SetJFListRowCount(const Value: Integer);
procedure SetJFDispSeparator(const Value: string);
procedure SetJFDDTItemID(const Value: string);
procedure SetJFDDTParentID(const Value: string);
function GetJFSelectParams(Key : Char): TJFSelectParams;
procedure SetDateTimeMask;
procedure SetJFSecVisible(const Value: Boolean);
procedure SetJFTimeVisible(const Value: Boolean);
procedure SetDispText;
procedure SetJFSelectIndex(const Value: Integer);
procedure StartTimer;
procedure StopTimer;
procedure SetJFDDNumSelect(const Value: Boolean);
procedure SetJFLimitSpace(const Value: Boolean);
procedure SetJFSRFocusMove(const Value: Boolean);
procedure SetJFEnterToSearch(const Value: Boolean);
procedure SetJFPacketRecords(const Value: Integer);
procedure SetJFClearDefIndex(const Value: Integer);
procedure SetJFSearchUseLocate(const Value: Boolean);
{ Private declarations }
protected
{ Protected declarations }
procedure Change; override;
procedure CreateParams( var Params: TCreateParams ); override;
procedure CreateWnd; override;
procedure SetEditRect; virtual;
procedure ResizeButton; virtual;
function GetSelText: string; override;
procedure ButtonClick(Sender: TObject);
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure ShowSelect(Key: Char); virtual;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Clear; override;
function IsSelectEmpty: Boolean;
function GetDropDownList: Boolean;
function IsVaildDateTime: Boolean;
property JFNumericValue: Extended read FJFNumericValue write SetJFNumericValue;
property JFDateValue : TDateTime read FJFDateValue write SetJFDateValue;
property JFSelectResult: TJFRecList read FJFSelectResult;
property JFDropDownList: TJFRecList read FJFDropDownList;
property JFSelectIndex : Integer write SetJFSelectIndex;
procedure SelectValue(AFieldName: string; AValue: Variant);
procedure JFButtonClick;
function GetFullSortValue: string; //获取分类值全称(包含所有父类)
published
{ Published declarations }
property JFEditKind : TJFButtonKind read FJFEditKind write SetJFEditKind; //编辑栏类型
property JFAlignment: TLeftRight read FJFAlignment write SetJFAlignment;
property JFButtonVisible: Boolean read GetButtonVisible write SetButtonVisible;
property JFButtonFlat: Boolean read GetButtonFlat write SetButtonFlat;
property JFSearchFields: TEdtSearchFields read FJFSearchFields write SetJFSearchFields;//查询选择列表查询的字段信息
property JFExecParams : TEdtExecParams read FJFExecParams write SetJFExecParams;//选择列表执行Sql语句的执行参数
property JFDispFields: TEdtDispFields read FJFDispFields write SetJFDispFields; //查询选择列表显示的字段信息
property OnButtonClick: TNotifyEvent read FOnButtonClick write SetOnButtonClick;
property JFSQLText: String read FJFSQLText write SetJFSQLText; //选择列表执行的SQL语句
property JFRemoteServer : TCustomRemoteServer read FJFRemoteServer write SetJFRemoteServer;
property BeforeShowSelect: TEdtBeforeShowSelect read FBeforeShowSelect write SetBeforeShowSelect;
property OnSelectReturn: TNotifyEvent read FOnSelectReturn write SetOnSelectReturn;
property JFFilterChars: string read FJFFilterChars write SetJFFilterChars;//不允许输入的字符
property JFInputChars : string read FJFInputChars write SetJFInputChars; //允许输入的字符
property JFFocusMove: Boolean read FJFFocusMove write SetJFFocusMove; //是否使用回车键和上下键自动移动焦点
property JFDecimalDigits: Integer read FJFDecimalDigits write SetJFDecimalDigits; //数值小数位
property JFMaxNumeric: Extended read FJFMaxNumeric write SetJFMaxNumeric; //数据最大值
property JFMinNumeric: Extended read FJFMinNumeric write SetJFMinNumeric; //数值最小值
property JFNumericLimit: Boolean read FJFNumericLimit write SetJFNumericLimit; //是否限制数值范围
property JFMsgClear: Boolean read FJFMsgClear write SetJFMsgClear; //是否接收消息清除编辑栏
property JFMultiSelect: Boolean read FJFMultiSelect write SetJFMultiSelect; //选择列表是否允许多选
property JFDispFieldName: string read FJFDispFieldName write SetJFDispFieldName; //编辑栏显示选择返回值的字段名称
property JFDispSeparator: string read FJFDispSeparator write SetJFDispSeparator;//多条记录显示分隔符
property JFBackspaceClear: Boolean read FJFBackspaceClear write SetJFBackspaceClear; //在ReadOnly状态下退格清除编辑栏
property JFListRowCount: Integer read FJFListRowCount write SetJFListRowCount;//显示选择列表行数
property JFDDTItemID : string read FJFDDTItemID write SetJFDDTItemID;
property JFDDTParentID: string read FJFDDTParentID write SetJFDDTParentID;
property JFTimeVisible: Boolean read FJFTimeVisible write SetJFTimeVisible; //是否显示时间
property JFSecVisible : Boolean read FJFSecVisible write SetJFSecVisible; //是否显示秒
property JFDDNumSelect: Boolean read FJFDDNumSelect write SetJFDDNumSelect;
property JFLimitSpace : Boolean read FJFLimitSpace write SetJFLimitSpace;
property JFSRFocusMove: Boolean read FJFSRFocusMove write SetJFSRFocusMove;
property JFPacketRecords: Integer read FJFPacketRecords write SetJFPacketRecords;
property JFEnterToSearch: Boolean read FJFEnterToSearch write SetJFEnterToSearch;
property JFClearDefIndex: Integer read FJFClearDefIndex write SetJFClearDefIndex;
property JFSearchUseLocate: Boolean read FJFSearchUseLocate write SetJFSearchUseLocate;
property Text: string read GetText write SetText;
property EditMask: TEditMask read GetEditMask write SetEditMask;
property Align;
property Anchors;
property AutoSelect;
property AutoSize;
property BiDiMode;
property CharCase;
property Color;
property Constraints;
property Ctl3D;
property DisabledColor;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property FocusColor;
property FrameColor;
property FrameController;
property FrameHotColor;
property FrameHotTrack;
property FrameHotStyle;
property FrameSides;
property FrameStyle;
property FrameVisible;
property FramingPreference;
property HideSelection;
property ImeMode;
property ImeName;
property MaxLength;
property OEMConvert;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PasswordChar;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOnEnter;
property TabOrder;
property TabStop;
property Visible;
property OnChange;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnMouseEnter;
property OnMouseLeave;
property OnStartDock;
property OnStartDrag;
end;
procedure Register;
function GetBtnEdtGlyph( Kind: TJFButtonKind ): TBitmap;
implementation
{$R JFEdit.res}
const
BtnEdtResNames: array[ TJFButtonKind ] of PChar = ( 'JFBTNEDT_LOOKUP',
'JFBTNEDT_LOOKUP',
'JFBTNEDT_CALCULATOR',
'JFBTNEDT_CALENDAR',
'JFBTNEDT_DROPDOWN',
'JFBTNEDT_DROPDOWN',
'JFBTNEDT_SEARCH',
'JFBTNEDT_FOLDER'
);
var
BtnEdtGlypJF: array[ TJFButtonKind ] of TBitmap;
function GetBtnEdtGlyph( Kind: TJFButtonKind ): TBitmap;
begin
if BtnEdtGlypJF[ Kind ] = nil then
begin
BtnEdtGlypJF[ Kind ] := TBitmap.Create;
BtnEdtGlypJF[ Kind ].LoadFromResourceName( HInstance, BtnEdtResNames[ Kind ] );
end;
Result := BtnEdtGlypJF[ Kind ];
end;
procedure Register;
begin
RegisterComponents('JFVCL', [TJFEdit]);
end;
{ TJFEdit }
procedure TJFEdit.ButtonClick(Sender: TObject);
begin
if csDesigning in ComponentState then
Exit;
if Assigned(FOnButtonClick) then
FOnButtonClick(Self);
case FJFEditKind of
JFbkNumeric,
JFbkDropDown,
JFbkDate,
JFbkDropDownTree,
JFbkSearch : ShowSelect(#0);
end;
end;
procedure TJFEdit.Change;
var
LFactor: Extended;
begin
inherited;
SetEditRect;
if Text = '' then
begin
Clear;
end;
case FJFEditKind of
JFbkNumeric : begin
try
LFactor := IntPower(10, FJFDecimalDigits);
FJFNumericValue := StrToFloatDef(inherited Text, 0);
if FJFNumericLimit then
begin
if FJFNumericValue > FJFMaxNumeric then
begin
FJFNumericValue := Trunc(FJFMaxNumeric * LFactor) / LFactor;
Exit;
end;
if FJFNumericValue < FJFminNumeric then
begin
FJFNumericValue := Trunc(FJFMinNumeric * LFactor) / LFactor;
Exit;
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -