Changeset 88


Ignore:
Timestamp:
Jan 3, 2022, 11:05:44 PM (2 years ago)
Author:
chronos
Message:
  • Modified: Code optimization and cleanup.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormContacts.pas

    r82 r88  
    201201      with TContact(List.Items[I]) do begin
    202202        FoundCount := 0;
    203         for J := 0 to FilterItems.Count - 1 do begin
    204           if FilterItems[J].FieldIndex = cfNone then begin
    205             for K := 0 to TContact(List.Items[I]).GetFields.Count - 1 do begin
    206               if Pos(UTF8LowerCase(FilterItems[J].Value),
    207                 UTF8LowerCase(TContact(List.Items[I]).Fields[TContact(List.Items[I]).GetFields[K].Index])) > 0 then begin
    208                   Inc(FoundCount);
    209                   Break;
    210                 end;
    211             end;
    212           end else begin
     203        for J := 0 to FilterItems.Count - 1 do
     204        if FilterItems[J].FieldIndex = cfNone then begin
     205          for K := 0 to TContact(List.Items[I]).GetFields.Count - 1 do begin
    213206            if Pos(UTF8LowerCase(FilterItems[J].Value),
    214               UTF8LowerCase(TContact(List.Items[I]).Fields[FilterItems[J].FieldIndex])) > 0 then
     207              UTF8LowerCase(TContact(List.Items[I]).Fields[TContact.GetFields[K].Index])) > 0 then begin
    215208                Inc(FoundCount);
     209                Break;
     210              end;
    216211          end;
     212        end else begin
     213          if Pos(UTF8LowerCase(FilterItems[J].Value),
     214            UTF8LowerCase(TContact(List.Items[I]).Fields[FilterItems[J].FieldIndex])) > 0 then
     215              Inc(FoundCount);
    217216        end;
    218         if FoundCount <> FilterItems.Count then List.Delete(I);
    219       end;
    220     end else
    221     if TContact(List.Items[I]) is TContact then begin
    222       List.Delete(I);
     217      end;
     218      if FoundCount <> FilterItems.Count then List.Delete(I);
    223219    end;
    224220  end;
     
    230226  FContacts := AValue;
    231227  ReloadList;
    232   UpdateInterface;
    233   ListViewFilter1.Reset;
     228  BeginUpdate;
     229  try
     230    ListViewFilter1.Reset;
     231  finally
     232    EndUpdate;
     233  end;
    234234end;
    235235
     
    280280  Field: TContactField;
    281281begin
    282   while ListView1.Columns.Count < ListViewColumns.Count do
    283     ListView1.Columns.Add;
    284   while ListView1.Columns.Count > ListViewColumns.Count do
    285     ListView1.Columns.Delete(ListView1.Columns.Count - 1);
    286   for I := 0 to ListView1.Columns.Count - 1 do begin
    287     if Assigned(Contacts) and Assigned(Contacts.ContactsFile) then begin
    288       Field := TContact.GetFields.GetByIndex(ListViewColumns[I]);
    289       if Assigned(Field) then
    290         ListView1.Columns[I].Caption := Field.Title;
    291     end;
     282  ListView1.Columns.BeginUpdate;
     283  try
     284    while ListView1.Columns.Count < ListViewColumns.Count do
     285      ListView1.Columns.Add;
     286    while ListView1.Columns.Count > ListViewColumns.Count do
     287      ListView1.Columns.Delete(ListView1.Columns.Count - 1);
     288    for I := 0 to ListView1.Columns.Count - 1 do begin
     289      if Assigned(Contacts) and Assigned(Contacts.ContactsFile) then begin
     290        Field := TContact.GetFields.GetByIndex(ListViewColumns[I]);
     291        if Assigned(Field) then
     292          ListView1.Columns[I].Caption := Field.Title;
     293      end;
     294    end;
     295  finally
     296    ListView1.Columns.EndUpdate;
    292297  end;
    293298end;
     
    558563
    559564  ListViewColumns := TContactFieldIndexes.Create;
    560   ListViewColumns.Add(cfFullName);
    561   ListViewColumns.Add(cfFirstName);
    562   ListViewColumns.Add(cfMiddleName);
    563   ListViewColumns.Add(cfLastName);
    564   ListViewColumns.Add(cfTel);
    565   ListViewColumns.Add(cfTelCell);
    566   ListViewColumns.Add(cfTelHome);
    567   ListViewColumns.Add(cfTelWork);
    568   ListViewColumns.Add(cfEmailWork);
     565  with ListViewColumns do begin
     566    Add(cfFullName);
     567    Add(cfFirstName);
     568    Add(cfMiddleName);
     569    Add(cfLastName);
     570    Add(cfTel);
     571    Add(cfTelCell);
     572    Add(cfTelHome);
     573    Add(cfTelWork);
     574    Add(cfEmailWork);
     575  end;
    569576
    570577  FContacts := nil;
  • trunk/UContact.pas

    r87 r88  
    945945    Prop := GetProperty(Field);
    946946    if Assigned(Prop) then begin
    947       Field := GetFields.GetByIndex(Index);
    948947      if Field.ValueIndex <> -1 then begin
    949948        Result := DecodeEscaped(Prop.ValueItem[Field.ValueIndex])
Note: See TracChangeset for help on using the changeset viewer.