Используйте Autocomplete Microsoft в потомке TCustomEdit
AutoComplete Microsoft может использоваться в приложениях Delphi дружественным способом со следующим компонентом:
unit U_AutoCompleteEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, StrTools, ShlIntf, ActiveX, ComObj;
type
TSearchListChangeEvent = procedure of object;
TAutoCompleteEdit = class(TCustomEdit)
private
FSearchListChange: TSearchListChangeEvent;
FAutoComplete: IAutoComplete2;
FStrings: IUnknown;
FStringList: TStrings;
procedure SetFStringList(const Value: TStrings);
protected
procedure SearchListChange;
public
constructor Create(AOwner: TComponent);override;
//Needed to init AutoComplete when the component is first Loaded
procedure Loaded;override;
destructor Destroy;override;
procedure SetAutoComplete;
published
property AutoSelect;
property AutoSize;
property BorderStyle;
property CharCase;
property HideSelection;
property MaxLength;
property ParentColor;
property Text;
property OnChange;
property SearchList: TStrings read FStringList write SetFStringList;
property OnSearchListChange: TSearchListChangeEvent read FSearchListChange
write FSearchListChange;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Sitio Web', [TAutoCompleteEdit]);
end;//end of Register
{ TAutoCompleteEdit }
constructor TAutoCompleteEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Parent := TWinControl(AOwner);
FStringList := TStringList.Create;
SearchListChange;
end;//end of TAutoCompleteEdit.Create
destructor TAutoCompleteEdit.Destroy;
begin
FStringList.Free;
inherited;
end;//end of TAutoCompleteEdit.Destroy
procedure TAutoCompleteEdit.Loaded;
begin
inherited;
if FStringList.Count > 0 then
SetAutoComplete;
end;//end of TAutoCompleteEdit.Loaded
procedure TAutoCompleteEdit.SearchListChange;
begin
if Assigned(FSearchListChange) then
FSearchListChange;
end;//end of TAutoCompleteEdit.SearchListChange
procedure TAutoCompleteEdit.SetAutoComplete;
begin
FAutoComplete := CreateComObject(CLSID_AutoComplete)as IAutoComplete2;
FStrings := TEnumString.Create(FStringList) as IUnknown;
OleCheck(FAutoComplete.SetOptions(ACO_AUTOSUGGEST
or ACO_AUTOAPPEND or ACO_UPDOWNKEYDROPSLIST or ACO_USETAB));
OleCheck(FAutoComplete.Init(Self.Handle, FStrings, nil, nil));
end;//end of TAutoCompleteEdit.SetAutoComplete
procedure TAutoCompleteEdit.SetFStringList(const Value: TStrings);
begin
SearchList.Assign(Value);
SetAutoComplete;
SearchListChange;
end;//end of TAutoCompleteEdit.SetFStringList
end.
Обратите внимание, что Вы можете использовать AutoComplete только с Shell32.dll версии 4.7 и выше. Так что, если у Вас установлен IE 5.0 и выше, то у Вас будет все работать.
По материалам http://delphi.3000.com
|