Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do a Case Statement with TEXT values...

How To

Do a Case Statement with TEXT values...

by  DelphiAaron  Posted    (Edited  )
1st add this function to your app.

Code:
function StringToCaseSelect(Selector : string;
 CaseList: array of string): Integer;
var cnt: integer;
begin
   Result:=-1;
   for cnt:=0 to Length(CaseList)-1 do
begin
     if CompareText(Selector, CaseList[cnt]) = 0 then
     begin
       Result:=cnt;
       Break;
     end;
   end;
end;

Usage:

Code:
case StringToCaseSelect(edit1.Text,['stringtocompareagainst1','stringtocompareagainst2','stringtocompareagainst3']) of
   0:ShowMessage('You picked string1') ;
   1:ShowMessage('You picked string2') ;
   2:ShowMessage('You picked string3') ;
end;
}
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top