Page 1 of 1

Duplicates

Posted: Tue Nov 02, 2010 9:03 pm
by atagal
Dimitris, how to remove duplicates in delphi?

Code: Select all

       lbl := TStringList.Create;
       lbl.Duplicates := dupIgnore;
       lbl.Sorted := True;

       i := 0;
       repeat
               sqrNum := GetPart (sCat, i, ';');
               if (sqrNum <> '') then lbl.Add(trim(sqrNum));
               i := i + 1;
       until sqrNum = '';

       sCat := lbl.CommaText;
       lbl.Free;
after many hours i finaly have found some solution but it works with "Sorted=True" only.

on discogs are a lot dublicates labels.
for example:
Cat1, Cat2, Cat3
Label1, Label1, Label2

i wish remove duplicates but not sort it. any hint?

Re: Duplicates

Posted: Wed Nov 03, 2010 8:17 am
by jtclipper
From a quick look I think you can use a for loop to iterate through the stringlist, check the value against the entries and add accordingly.

Code: Select all

 procedure _add_to_list;
 var 
   j: integer;
 begin
   if (sqrNum = '') then exit; // get out
   for j := 0 to lbl.Count - 1 do begin
       if lbl.Strings[ j ] = sqrNum then exit; //get out
   end;
   lbl.Add( sqrNum );
 end;


 lbl := TStringList.Create;

 i := 0;
 repeat
    sqrNum := Trim( GetPart(sCat, i, ';') );
    _add_to_list;
    Inc( i );
 until sqrNum = '';

 sCat := lbl.CommaText;
 lbl.Free;

Re: Duplicates

Posted: Wed Nov 03, 2010 9:50 am
by atagal
perfect! thank you!