Re: How do you do a Switch statement in Delphi?



Kent Briggs schrieb:
Oliver Townshend wrote:

You'll have to do an IF/THEN/ELSE.

Or put all the strings in a tstringlist and do something like

i:=mystringlist.indexof(mystring);
case i of
0: //
1: //
2: //
end;



Or this one:

....
uses StrUtils;

....

case IndexText('checkbox', ['checkbox', 'panel']) of
0: Label1.Caption := 'checkbox';
1: Label1.Caption := 'panel';
else
Label1.Caption := 'default';
end;

If you want it case-sensitive use IndexStr instead of IndexText.

Uwe Raabe
.