source: tags/1.4.0/Forms/UFormFind.pas

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