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


To add or not to add


Reply
Views: 1560  
Thread Tools Rate Thread
  #1  
Old 08-20-2010, 10:53 AM
bholas bholas is offline
Award Winner
 
Join Date: Apr 2010
Posts: 4,977
Default To add or not to add

Here's a function that will check if a given string exist in a string list. You can use it when you want to add only the unique strings to any object with a string list property such as list boxes, memos, etc.
function StrIsInList(
sl : TStrings;
s : string;
bCaseSensitive : boolean )
: boolean;
var
n : integer;
begin
Result := False;
if( not bCaseSensitive )then
s := LowerCase( s );
for n := 0 to ( sl.Count - 1 ) do
begin
if( ( bCaseSensitive and
( s = LowerCase(
sl.Strings[ n ] ) ) )
or ( s = sl.Strings[ n ] )
)then
begin
Result := True;
Exit;
end;
end;
end;

//
// example on how to use StrIsInList()
//
procedure
TForm1.****on1Click(Sender: TObject);
begin
if( not StrIsInList( ListBox1.Items,
Edit1.Text, False ) ) then
ListBox1.Items.Add( Edit1.Text );
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)