DelphiFAQ Home Search:
General :: Programming :: Delphi
General Delphi related information.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.
Recommended links on this topic:
Featured Article

Avoid duplicate items in string lists

The following code shows how to use the property Duplicates to avoid duplicate items in string lists:

var
   sl : TStringList;
 begin
   sl := TStringList.Create;
   with sl do
   begin
     Sorted     := True;
     Duplicates := dupIgnore;
 
     //
     // add your items here
     // all the duplicate items
     // will be ignored
     //
     Add(Input1.text);
   end;
 
   //
   // now you can assign the
   // string list with unique
   // items to listbox1 (example)
   //
   ListBox1.Items.Assign(sl);
   sl.Free;
 end;
You don't like the formatting? Check out SourceCoder then!
Generated 4:01:56 on Sep 23, 2017