Changeset 32 for trunk/Forms/UFormContacts.pas
- Timestamp:
- Nov 25, 2021, 11:32:55 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormContacts.pas
r31 r32 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 ComCtrls, Menus, ActnList, UContact ;9 ComCtrls, Menus, ActnList, UContact, UListViewSort, fgl, LazUTF8; 10 10 11 11 type … … 20 20 ActionList1: TActionList; 21 21 ListView1: TListView; 22 ListViewFilter1: TListViewFilter; 23 ListViewSort1: TListViewSort; 22 24 MenuItem1: TMenuItem; 23 25 MenuItem2: TMenuItem; … … 40 42 procedure ListView1SelectItem(Sender: TObject; Item: TListItem; 41 43 Selected: Boolean); 44 procedure ListViewFilter1Change(Sender: TObject); 45 procedure ListViewSort1ColumnWidthChanged(Sender: TObject); 46 function ListViewSort1CompareItem(Item1, Item2: TObject): Integer; 47 procedure ListViewSort1Filter(ListViewSort: TListViewSort); 42 48 private 43 49 FContacts: TContacts; 50 procedure FilterList(List: TFPGObjectList<TObject>); 44 51 procedure SetContacts(AValue: TContacts); 45 52 public … … 68 75 procedure TFormContacts.ListView1Data(Sender: TObject; Item: TListItem); 69 76 begin 70 if Assigned(Contacts) and (Item.Index < Contacts.Count)then71 with TContact( Contacts[Item.Index]) do begin77 if Item.Index < ListViewSort1.List.Count then 78 with TContact(ListViewSort1.List[Item.Index]) do begin 72 79 Item.Caption := Fields[cfFullName]; 73 80 Item.SubItems.Add(Fields[cfFirstName]); … … 91 98 end; 92 99 100 procedure TFormContacts.ListViewFilter1Change(Sender: TObject); 101 begin 102 ReloadList; 103 end; 104 105 procedure TFormContacts.ListViewSort1ColumnWidthChanged(Sender: TObject); 106 begin 107 ListViewFilter1.UpdateFromListView(ListView1); 108 end; 109 110 function TFormContacts.ListViewSort1CompareItem(Item1, Item2: TObject): Integer; 111 begin 112 Result := 0; 113 if Assigned(Item1) and Assigned(Item2) and (ListViewSort1.Order <> soNone) then begin 114 with ListViewSort1 do 115 case Column of 116 0: Result := CompareString(TContact(Item1).Fields[cfFullName], TContact(Item2).Fields[cfFullName]); 117 1: Result := CompareString(TContact(Item1).Fields[cfFirstName], TContact(Item2).Fields[cfFirstName]); 118 2: Result := CompareString(TContact(Item1).Fields[cfMiddleName], TContact(Item2).Fields[cfMiddleName]); 119 3: Result := CompareString(TContact(Item1).Fields[cfLastName], TContact(Item2).Fields[cfLastName]); 120 4: Result := CompareString(TContact(Item1).Fields[cfTelCell], TContact(Item2).Fields[cfTelCell]); 121 5: Result := CompareString(TContact(Item1).Fields[cfTelHome], TContact(Item2).Fields[cfTelHome]); 122 end; 123 if ListViewSort1.Order = soDown then Result := -Result; 124 end else Result := 0; 125 end; 126 127 procedure TFormContacts.ListViewSort1Filter(ListViewSort: TListViewSort); 128 begin 129 if Assigned(Contacts) then Contacts.AssignToList(ListViewSort1.List) 130 else ListViewSort1.List.Clear; 131 FilterList(ListViewSort1.List); 132 end; 133 134 procedure TFormContacts.FilterList(List: TFPGObjectList<TObject>); 135 var 136 I: Integer; 137 FoundCount: Integer; 138 EnteredCount: Integer; 139 begin 140 EnteredCount := ListViewFilter1.TextEnteredCount; 141 for I := List.Count - 1 downto 0 do begin 142 if List.Items[I] is TContact then begin 143 with TContact(List.Items[I]) do begin 144 with ListViewFilter1 do 145 if Visible and (EnteredCount > 0) then begin 146 FoundCount := 0; 147 if Pos(UTF8LowerCase(StringGrid.Cells[0, 0]), 148 UTF8LowerCase(TContact(List.Items[I]).Fields[cfFullName])) > 0 then Inc(FoundCount); 149 if Pos(UTF8LowerCase(StringGrid.Cells[1, 0]), 150 UTF8LowerCase(TContact(List.Items[I]).Fields[cfFirstName])) > 0 then Inc(FoundCount); 151 if Pos(UTF8LowerCase(StringGrid.Cells[2, 0]), 152 UTF8LowerCase(TContact(List.Items[I]).Fields[cfMiddleName])) > 0 then Inc(FoundCount); 153 if Pos(UTF8LowerCase(StringGrid.Cells[3, 0]), 154 UTF8LowerCase(TContact(List.Items[I]).Fields[cfLastName])) > 0 then Inc(FoundCount); 155 if Pos(UTF8LowerCase(StringGrid.Cells[4, 0]), 156 UTF8LowerCase(TContact(List.Items[I]).Fields[cfTelCell])) > 0 then Inc(FoundCount); 157 if Pos(UTF8LowerCase(StringGrid.Cells[5, 0]), 158 UTF8LowerCase(TContact(List.Items[I]).Fields[cfTelHome])) > 0 then Inc(FoundCount); 159 if FoundCount <> EnteredCount then List.Delete(I); 160 end; 161 end; 162 end else 163 if TContact(List.Items[I]) is TContact then begin 164 List.Delete(I); 165 end; 166 end; 167 end; 168 93 169 procedure TFormContacts.SetContacts(AValue: TContacts); 94 170 begin … … 106 182 ReloadList; 107 183 UpdateInterface; 184 ListViewFilter1.UpdateFromListView(ListView1); 108 185 end; 109 186 … … 182 259 procedure TFormContacts.ReloadList; 183 260 begin 184 if Assigned(Contacts) then 185 ListView1.Items.Count := Contacts.Count 186 else ListView1.Items.Count := 0; 187 ListView1.Refresh; 261 ListViewSort1.Refresh; 188 262 end; 189 263
Note:
See TracChangeset
for help on using the changeset viewer.