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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to do a Case Statement for TEXT values... 1

Status
Not open for further replies.

PaidtheUmpire

Programmer
Jan 4, 2004
105
AU
I want to create a "case"-like statement which would look something like this...

<code>Case OutputType.Text if
'KML - GoogleEarth' : GoogleEarthLine;
'XXX - Other' : OtherLine;</code>

Otherwise i might need a large amount of the following...
<code>If OutputType.Text = 'KML - GoogleEarth'
then GoogleEarthLine;</code>


Any ideas?

Delphi, Delphi, Delphi. Oi! Oi! Oi!
 
Since .NET supports this you almost certainly can with Delphi 2005, but not with tradional Delphi


Hope this helps.

[vampire][bat]
 
Thanks,

Pity i'm using Delphi 7 then huh :p


Thanks again...

Delphi, Delphi, Delphi. Oi! Oi! Oi!
 
The following function enables you to use the Case statement with string type variables:
~~~~~~~~~~~~~~~~~~~~~~~~~
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:

case StringToCaseSelect(OutputType.Text,
      ['KML - GoogleEarth','XXX - Other','XXX - Other2']) of
   0:ShowMessage('You picked KML - GoogleEarth') ;
   1:ShowMessage('You picked Other') ;
   2:ShowMessage('You picked Other2') ;
end;
}


Aaron Taylor
John Mutch Electronics
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top