source: trunk/Forms/FormFind.pas

Last change on this file was 162, checked in by chronos, 17 months ago
  • Modified: Updated Common package.
File size: 3.2 KB
Line 
1unit FormFind;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
7 ExtCtrls, StdCtrls, ActnList, Menus, VCard, FormContacts, FormEx;
8
9type
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
36implementation
37
38{$R *.lfm}
39
40resourcestring
41 SAny = 'Any';
42
43{ TFormFind }
44
45procedure TFormFind.SetContacts(AValue: TContacts);
46var
47 ContactField: TContactField;
48 Items: TStringList;
49 I: Integer;
50begin
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;
76end;
77
78procedure TFormFind.Find;
79begin
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;
87end;
88
89procedure TFormFind.FormCreate(Sender: TObject);
90begin
91 ContactFieldIndex := cfNone;
92
93 FormContacts := TFormContacts.Create(nil);
94 FormContacts.ListViewFilter1.Visible := False;
95end;
96
97procedure TFormFind.ComboBoxFieldChange(Sender: TObject);
98var
99 ContactField: TContactField;
100begin
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;
108end;
109
110procedure TFormFind.EditValueKeyPress(Sender: TObject; var Key: char);
111begin
112 if Key = #13 then Find;
113end;
114
115procedure TFormFind.ButtonFindClick(Sender: TObject);
116begin
117 Find;
118end;
119
120procedure TFormFind.FormDestroy(Sender: TObject);
121begin
122 FreeAndNil(FormContacts);
123end;
124
125procedure TFormFind.FormShow(Sender: TObject);
126begin
127 FormContacts.ManualDock(Self, nil, alClient);
128 FormContacts.Align := alClient;
129 FormContacts.Show;
130
131 Find;
132end;
133
134end.
135
Note: See TracBrowser for help on using the repository browser.