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