Go Back   Wiki NewForum | Latest Entertainment News > Career Forum & Tips > Tech Forum & Tutorial > Oracle Database, SQL, Application, Programming


Easy way to avoid adding duplicate items to string lists


Reply
Views: 2167  
Thread Tools Rate Thread
  #1  
Old 08-20-2010, 11:04 AM
bholas bholas is offline
Award Winner
 
Join Date: Apr 2010
Posts: 4,977
Default Easy way to avoid adding duplicate items to string lists

String lists (TStringList) are great -- easy to manage, used by many components such as memos, list boxes, combo boxes, etc., and full of features. Here's how to avoid adding duplicate items to 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( edit1.text );
end;

//
// now you can assign the
// string list with unique
// items to listbox1 (example)
//
listbox1.Items.Assign( sl );

sl.Free;
end;

Reply With Quote
Reply

Tags
programming tips

New topics in Oracle Database, SQL, Application, Programming





Powered by vBulletin® Version 3.8.10
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
WikiNewForum)