Home > Back-end >  A custom filter input control, master please help!
A custom filter input control, master please help!

Time:09-17

Maintain an old Delphi project recently, want to customize a control, dynamic filtering based on user input data, because ability is limited, and nearly ten years have not used the Delphi, feeling a little overwhelmed, for help here, can filter the current control, but can only enter one character at a time, problems should be input character popup list after Edit lost focus, warrior please help solve, thank you so much!

TFilterEdit expanded the TButtonEdit,, TButtonEdit expanded the TCustomEdit just integrates a Button without other extensions, so it can replace with TCustomEdit TButtonEdit, because must maintain the project is based on the object, so that defines a class TBaseItem, controls a TBaseItem list, according to user input from the list to filter the data, display the drop-down ListBox in the form, then can use the cursor keys to select,

Code for reference some examples downloaded from the Internet,

 
The unit FilterEdit;

Interface

USES Classes, Controls, Messages, Windows, Forms, StdCtrls, ButtonEdit;

Type
TBaseItem=class
Private
FInCode: string;
FDispCode: string;
FDispName: string;
FHintCode: string;
Public
The function MatchItem (const value: string) : Boolean;
The property InCode: string read FInCode write FInCode;
The property DispCode: string read FDispCode write FDispCode;
The property DispName: string read FDispName write FDispName;
The property HintCode: string read FHintCode write FHintCode;
end;

TDropWindow=class;

TFilterEdit=class (TButtonEdit)
Private
FDropDown: Boolean;
FDropWindow: TDropWindow;
FWindowHeight: integer;
FWindowWidth: integer;
FItemList: TStrings;
FFilterItemList: TStrings;
FSelectedItem: TBaseItem;

Procedure SetWindowWidth (const value: integer);
Procedure SetWindowHeight (const value: integer);
Procedure SetWindowPosition (var point: TPoint);
Procedure SetSelectedItem (value: TBaseItem);
Procedure SetItemList (const value: TStrings);
The function GetItemCount: integer;
Protected
//procedure Change. Override.
Procedure DropDown can; Virtual;
Procedure CloseUp; Virtual;
Procedure WMKillFocus (var Msg: TWMKillFocus); The message WM_KILLFOCUS;
Procedure WMChar (var Msg: TWMChar); The message WM_CHAR;
Procedure MouseDown (Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer); Override.
//
Procedure RefreshFilterList (filter: string);
Public
The constructor Create (AOwner: TComponent); Override.
The destructor Destroy; Override.
The property SelectedItem: TBaseItem read FSelectedItem write SetSelectedItem;
The property ItemCount: integer read GetItemCount;
The property Items: TStrings read FItemList write SetItemList;
Published
The property DropWindowWidth: integer read FWindowWidth write SetWindowWidth;
The property DropWindowHeight: integer read FWindowHeight write SetWindowHeight;
end;

TDropWindow=class (TCustomForm)
Private
FListBox: TListBox;
Procedure WMMouseActivate (var Msg: TMessage); The message WM_MOUSEACTIVATE;
Procedure WMActivate (var Msg: TWMActivate); The message WM_ACTIVATE;
The function GetForm: TWinControl;
Procedure ListBoxKeyPress (Sender: TObject; Var Key: Char);
Procedure SelectData (Sender: TObject);
Procedure RefreshList;
The function GetEdit: TFilterEdit;
Protected
Procedure CreateParams (var Params: TCreateParams); Override.
Procedure DoShow; Override.
Public
The constructor Create (AOwner: TComponent); Override.
The destructor Destroy; Override.
The property ListBox: TListBox read FListBox write FListBox;
The property Edit: TFilterEdit read GetEdit;
end;

Procedure Register;

Implementation

Procedure Register;
The begin
RegisterComponents (' DYF, [TFilterEdit]);
//RegisterPropertyEditor (TypeInfo (string), TButtonEdit, 'SelectField, TSelectFieldEditer);
end;

{TBaseItem}

The function TBaseItem. MatchItem (const value: string) : Boolean;
The begin
Result:=(Pos (value, self. FDispCode) & gt; 0) or (Pos (value, self. FHintCode) & gt; 0)
Or (Pos (value, self. FDispName) & gt; 0);
end;

{TFilterEdit}

The constructor TFilterEdit. Create (AOwner: TComponent);
The begin
Inherited;

Self. FItemList:=TStringList. Create;
Self. FFilterItemList:=TStringList. Create;

Self. FDropWindow:=TDropWindow. Create (self);
Self. FWindowWidth:=200;
Self. FWindowHeight:=80;
Self. FDropWindow. Width:=200;
Self. FDropWindow. Height:=80;
Self. FDropDown:=false;
end;

Destructor TFilterEdit. Destroy;
The begin
Self. FDropWindow. Free;
Self. FFilterItemList. The Clear;
Self. FFilterItemList. Free;
Self. FItemList. The Clear;
Self. FItemList. Free;

Inherited;
end;

Procedure TFilterEdit. DropDown can;
Var
P: TPoint;
The begin
Self. FDropWindow. Color: Color=;
Self. FDropWindow. The Font. The Assign (Font);
P:=Parent ClientToScreen (Point (self. Left, the self. The Top + self. Height));
SetWindowPosition (p);

Self. FDropWindow. Top:=p.Y;
Self. FDropWindow. Left:=p.X;
Self. FDropWindow. Show;
Invalidate.
//Windows. SetFocus (self. FDropWindow. Handle).
Self. FDropDown:=true;
//self. SetFocus;
end;

Procedure TFilterEdit. CloseUp;
The begin
Self. FDropWindow. Hide; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related