source: tags/1.2.0/Forms/UFormFind.pas

Last change on this file was 76, checked in by chronos, 3 years ago
  • Added: Find dialog to search text value by given contact field or by any field.
File size: 3.7 KB
Line 
1unit UFormFind;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
9 ExtCtrls, StdCtrls, ActnList, Menus, fgl, UContact, UFormContacts;
10
11type
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
38var
39 FormFind: TFormFind;
40
41
42implementation
43
44{$R *.lfm}
45
46uses
47 UCore;
48
49resourcestring
50 SAny = 'Any';
51
52{ TFormFind }
53
54procedure TFormFind.SetContacts(AValue: TContacts);
55var
56 ContactField: TContactField;
57 Items: TStringList;
58 I: Integer;
59begin
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;
85end;
86
87procedure TFormFind.Find;
88begin
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;
96end;
97
98procedure TFormFind.FormCreate(Sender: TObject);
99begin
100 Core.Translator.TranslateComponentRecursive(Self);
101 Core.ThemeManager1.UseTheme(Self);
102 ContactFieldIndex := cfNone;
103
104 FormContacts := TFormContacts.Create(nil);
105 FormContacts.ListViewFilter1.Visible := False;
106end;
107
108procedure TFormFind.ComboBoxFieldChange(Sender: TObject);
109var
110 ContactField: TContactField;
111begin
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;
119end;
120
121procedure TFormFind.EditValueKeyPress(Sender: TObject; var Key: char);
122begin
123 if Key = #13 then Find;
124end;
125
126procedure TFormFind.ButtonFindClick(Sender: TObject);
127begin
128 Find;
129end;
130
131procedure TFormFind.FormClose(Sender: TObject;
132 var CloseAction: TCloseAction);
133begin
134 Core.PersistentForm1.Save(Self);
135end;
136
137procedure TFormFind.FormDestroy(Sender: TObject);
138begin
139 FreeAndNil(FormContacts);
140end;
141
142procedure TFormFind.FormShow(Sender: TObject);
143begin
144 Core.PersistentForm1.Load(Self);
145
146 FormContacts.ManualDock(Self, nil, alClient);
147 FormContacts.Align := alClient;
148 FormContacts.Show;
149
150 Find;
151end;
152
153end.
154
Note: See TracBrowser for help on using the repository browser.