Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
how to use a edit control with AutoComplete Capabilities Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
19-Aug-03
Category
VCL-General
Language
Delphi 3.x
Views
129
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jorge Abel Ayala Marentes

Microsoft´s AutoComplete can be used in a Delphi Application in a Friendly way with 
the following component

Answer:
1   
2   // Implements a TCustomEdit with AutoComplete Capabilities
3   // Author: Jorge Abel Ayala Marentes
4   // Created: 15/Oct/2000
5   // Last Modification: 21/Nov/2000
6   
7   unit U_AutoCompleteEdit;
8   
9   interface
10  
11  uses
12    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
13    StdCtrls, StrTools, ShlIntf, ActiveX, ComObj;
14  
15  type
16    TSearchListChangeEvent = procedure of object;
17  
18    TAutoCompleteEdit = class(TCustomEdit)
19    private
20      FSearchListChange: TSearchListChangeEvent;
21      FAutoComplete: IAutoComplete2;
22      FStrings: IUnknown;
23      FStringList: TStrings;
24      procedure SetFStringList(const Value: TStrings);
25    protected
26      procedure SearchListChange;
27    public
28      constructor Create(AOwner: TComponent); override;
29  
30      //Needed to init AutoComplete when the component is first Loaded
31      procedure Loaded; override;
32      destructor Destroy; override;
33      procedure SetAutoComplete;
34    published
35      property AutoSelect;
36      property AutoSize;
37      property BorderStyle;
38      property CharCase;
39      property HideSelection;
40      property MaxLength;
41      property ParentColor;
42      property Text;
43      property OnChange;
44      property SearchList: TStrings read FStringList write SetFStringList;
45      property OnSearchListChange: TSearchListChangeEvent read FSearchListChange
46        write FSearchListChange;
47    end;
48  
49  procedure register;
50  
51  implementation
52  
53  procedure register;
54  begin
55    RegisterComponents('Sitio Web', [TAutoCompleteEdit]);
56  end; //end of Register
57  
58  { TAutoCompleteEdit }
59  
60  constructor TAutoCompleteEdit.Create(AOwner: TComponent);
61  begin
62    inherited Create(AOwner);
63    Parent := TWinControl(AOwner);
64    FStringList := TStringList.Create;
65    SearchListChange;
66  end; //end of TAutoCompleteEdit.Create
67  
68  destructor TAutoCompleteEdit.Destroy;
69  begin
70    FStringList.Free;
71    inherited;
72  end; //end of TAutoCompleteEdit.Destroy
73  
74  //Updated: Last version didt´nt work because the searchlist wasn´t
75  //initializaed when the component was loaded :)
76  
77  procedure TAutoCompleteEdit.Loaded;
78  begin
79    inherited;
80    if FStringList.Count > 0 then
81      SetAutoComplete;
82  end; //end of TAutoCompleteEdit.Loaded
83  
84  procedure TAutoCompleteEdit.SearchListChange;
85  begin
86    if Assigned(FSearchListChange) then
87      FSearchListChange;
88  end; //end of TAutoCompleteEdit.SearchListChange
89  
90  procedure TAutoCompleteEdit.SetAutoComplete;
91  begin
92    FAutoComplete := CreateComObject(CLSID_AutoComplete) as IAutoComplete2;
93  
94    FStrings := TEnumString.Create(FStringList) as IUnknown;
95    OleCheck(FAutoComplete.SetOptions(ACO_AUTOSUGGEST
96      or ACO_AUTOAPPEND or ACO_UPDOWNKEYDROPSLIST or ACO_USETAB));
97    OleCheck(FAutoComplete.Init(Self.Handle, FStrings, nil, nil));
98  end; //end of TAutoCompleteEdit.SetAutoComplete
99  
100 procedure TAutoCompleteEdit.SetFStringList(const Value: TStrings);
101 begin
102   SearchList.Assign(Value);
103   SetAutoComplete;
104   SearchListChange;
105 end; //end of TAutoCompleteEdit.SetFStringList
106 
107 end.


You can download the complete component. 

Please note that AutoComplete can only be used if you have Sell32.dll verson 4.7 or 
above, I think that if you install IE 5.0 or above you won´t have any troble, there 
are still some improvements I can think of, but please any feedback will be 
apreciated, let me kwnow your ideas. 


Component Download: http://www.baltsoft.com/files/dkb/attachment/AutoCompleteEdit.zip

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC