1 | unit FormFind;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
---|
7 | ExtCtrls, StdCtrls, ActnList, Menus, VCard, FormContacts, FormEx;
|
---|
8 |
|
---|
9 | type
|
---|
10 |
|
---|
11 | { TFormFind }
|
---|
12 |
|
---|
13 | TFormFind = class(TFormEx)
|
---|
14 | ButtonFind: TButton;
|
---|
15 | ComboBoxField: TComboBox;
|
---|
16 | EditValue: TEdit;
|
---|
17 | Label1: TLabel;
|
---|
18 | Panel1: TPanel;
|
---|
19 | procedure ButtonFindClick(Sender: TObject);
|
---|
20 | procedure ComboBoxFieldChange(Sender: TObject);
|
---|
21 | procedure EditValueKeyPress(Sender: TObject; var Key: char);
|
---|
22 | procedure FormCreate(Sender: TObject);
|
---|
23 | procedure FormDestroy(Sender: TObject);
|
---|
24 | procedure FormShow(Sender: TObject);
|
---|
25 | private
|
---|
26 | FContacts: TContacts;
|
---|
27 | FormContacts: TFormContacts;
|
---|
28 | procedure SetContacts(AValue: TContacts);
|
---|
29 | public
|
---|
30 | ContactFieldIndex: TContactFieldIndex;
|
---|
31 | procedure Find;
|
---|
32 | property Contacts: TContacts read FContacts write SetContacts;
|
---|
33 | end;
|
---|
34 |
|
---|
35 |
|
---|
36 | implementation
|
---|
37 |
|
---|
38 | {$R *.lfm}
|
---|
39 |
|
---|
40 | resourcestring
|
---|
41 | SAny = 'Any';
|
---|
42 |
|
---|
43 | { TFormFind }
|
---|
44 |
|
---|
45 | procedure TFormFind.SetContacts(AValue: TContacts);
|
---|
46 | var
|
---|
47 | ContactField: TContactField;
|
---|
48 | Items: TStringList;
|
---|
49 | I: Integer;
|
---|
50 | begin
|
---|
51 | if FContacts = AValue then Exit;
|
---|
52 | FContacts := AValue;
|
---|
53 | if Assigned(FContacts) then begin
|
---|
54 | Items := TStringList.Create;
|
---|
55 | try
|
---|
56 | TContact.GetFields.LoadToStrings(Items);
|
---|
57 |
|
---|
58 | // Remove fields which are not used in contacts
|
---|
59 | for I := Items.Count - 1 downto 0 do
|
---|
60 | if Contacts.CountByField(TContactField(Items.Objects[I]).Index) = 0 then
|
---|
61 | Items.Delete(I);
|
---|
62 |
|
---|
63 | Items.InsertObject(0, SAny, nil);
|
---|
64 | ComboBoxField.Items.Assign(Items);
|
---|
65 | finally
|
---|
66 | Items.Free;
|
---|
67 | end;
|
---|
68 | ContactField := TContact.GetFields.GetByIndex(ContactFieldIndex);
|
---|
69 | ComboBoxField.ItemIndex := ComboBoxField.Items.IndexOfObject(ContactField);
|
---|
70 | if (ComboBoxField.Items.Count > 0) and (ComboBoxField.ItemIndex = -1) then
|
---|
71 | ComboBoxField.ItemIndex := 0;
|
---|
72 | end else begin
|
---|
73 | ComboBoxField.Clear;
|
---|
74 | end;
|
---|
75 | FormContacts.Contacts := Contacts;
|
---|
76 | end;
|
---|
77 |
|
---|
78 | procedure TFormFind.Find;
|
---|
79 | begin
|
---|
80 | with FormContacts.FilterItems do begin
|
---|
81 | Clear;
|
---|
82 | if EditValue.Text <> '' then
|
---|
83 | AddNew(ContactFieldIndex, EditValue.Text);
|
---|
84 | end;
|
---|
85 | FormContacts.ReloadList;
|
---|
86 | FormContacts.UpdateInterface;
|
---|
87 | end;
|
---|
88 |
|
---|
89 | procedure TFormFind.FormCreate(Sender: TObject);
|
---|
90 | begin
|
---|
91 | ContactFieldIndex := cfNone;
|
---|
92 |
|
---|
93 | FormContacts := TFormContacts.Create(nil);
|
---|
94 | FormContacts.ListViewFilter1.Visible := False;
|
---|
95 | end;
|
---|
96 |
|
---|
97 | procedure TFormFind.ComboBoxFieldChange(Sender: TObject);
|
---|
98 | var
|
---|
99 | ContactField: TContactField;
|
---|
100 | begin
|
---|
101 | if ComboBoxField.ItemIndex <> -1 then begin
|
---|
102 | ContactField := TContactField(ComboBoxField.Items.Objects[ComboBoxField.ItemIndex]);
|
---|
103 | if Assigned(ContactField) then
|
---|
104 | ContactFieldIndex := ContactField.Index
|
---|
105 | else ContactFieldIndex := cfNone;
|
---|
106 | end else ContactFieldIndex := cfNone;
|
---|
107 | Find;
|
---|
108 | end;
|
---|
109 |
|
---|
110 | procedure TFormFind.EditValueKeyPress(Sender: TObject; var Key: char);
|
---|
111 | begin
|
---|
112 | if Key = #13 then Find;
|
---|
113 | end;
|
---|
114 |
|
---|
115 | procedure TFormFind.ButtonFindClick(Sender: TObject);
|
---|
116 | begin
|
---|
117 | Find;
|
---|
118 | end;
|
---|
119 |
|
---|
120 | procedure TFormFind.FormDestroy(Sender: TObject);
|
---|
121 | begin
|
---|
122 | FreeAndNil(FormContacts);
|
---|
123 | end;
|
---|
124 |
|
---|
125 | procedure TFormFind.FormShow(Sender: TObject);
|
---|
126 | begin
|
---|
127 | FormContacts.ManualDock(Self, nil, alClient);
|
---|
128 | FormContacts.Align := alClient;
|
---|
129 | FormContacts.Show;
|
---|
130 |
|
---|
131 | Find;
|
---|
132 | end;
|
---|
133 |
|
---|
134 | end.
|
---|
135 |
|
---|