Mega Code Archive

 
Categories / Delphi / Examples
 

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;