Changeset 126 for trunk/UContact.pas


Ignore:
Timestamp:
Apr 6, 2022, 11:36:27 AM (2 years ago)
Author:
chronos
Message:
  • Added: Action to remove exact duplicates.
  • Modified: Test cases definition moved to separate file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UContact.pas

    r120 r126  
    136136      NoGroups: TStringArray): Boolean;
    137137    procedure Assign(Source: TContactProperty);
     138    function CompareTo(ContactProperty: TContactProperty): Boolean;
    138139    constructor Create;
    139140    destructor Destroy; override;
     
    179180    procedure Assign(Source: TContact);
    180181    function UpdateFrom(Source: TContact): Boolean;
     182    function CompareTo(Contact: TContact): Boolean;
    181183    constructor Create;
    182184    destructor Destroy; override;
     
    208210    procedure Merge(Contact: TContact; FieldIndex: TContactFieldIndex);
    209211    function ToString: ansistring; override;
     212    procedure RemoveExactDuplicates;
    210213  end;
    211214
     
    10491052end;
    10501053
     1054function TContactProperty.CompareTo(ContactProperty: TContactProperty): Boolean;
     1055var
     1056  I: Integer;
     1057begin
     1058  Result := (Name = ContactProperty.Name) and (Value = ContactProperty.Value) and
     1059    (Attributes.Count = ContactProperty.Attributes.Count);
     1060  if Result then begin
     1061    for I := 0 to Attributes.Count - 1 do
     1062    if not (Attributes[I] = ContactProperty.Attributes[I]) then begin
     1063      Result := False;
     1064      Break;
     1065    end;
     1066  end;
     1067end;
     1068
    10511069constructor TContactProperty.Create;
    10521070begin
     
    10801098
    10811099procedure TContacts.AddContacts(Contacts: TContacts);
    1082 var
    1083   I: Integer;
    1084   NewContact: TContact;
    1085 begin
    1086   for I := 0 to Contacts.Count - 1 do begin
    1087     NewContact := TContact.Create;
    1088     NewContact.Assign(Contacts[I]);
    1089     NewContact.ContactsFile := ContactsFile;
    1090     Add(NewContact);
    1091   end;
     1100begin
     1101  InsertContacts(Count, Contacts);
    10921102end;
    10931103
     
    11041114    Inc(Index);
    11051115  end;
     1116end;
     1117
     1118procedure TContacts.RemoveExactDuplicates;
     1119var
     1120  I: Integer;
     1121  J: Integer;
     1122begin
     1123  for I := 0 to Count - 1 do
     1124    for J := Count - 1 downto I + 1 do
     1125      if Items[I].CompareTo(Items[J]) then begin
     1126        Remove(Items[J]);
     1127      end;
    11061128end;
    11071129
     
    15541576end;
    15551577
     1578function TContact.CompareTo(Contact: TContact): Boolean;
     1579var
     1580  I: Integer;
     1581begin
     1582  Result := Properties.Count = Contact.Properties.Count;
     1583  if Result then begin
     1584    for I := 0 to Properties.Count - 1 do
     1585    if not Properties[I].CompareTo(Contact.Properties[I]) then begin
     1586      Result := False;
     1587      Break;
     1588    end;
     1589  end;
     1590end;
     1591
    15561592constructor TContact.Create;
    15571593begin
Note: See TracChangeset for help on using the changeset viewer.