可使用如下方法: case stringindex(edit.text,[caselist1,caselist2,caselist3]) of 1:statement1; 2:statement2; 3:statement3; end; casseasd stringindex()函数实现如下: function stringindex(const searchstring:string;strlist:array of string):integer; var i:integer; begin result:=-1; for i:=0 to high(strlist) do if comparetext(searchstring,strlist[i])=0 then begin result:=i; break; end; end;
ZT: const TypeArray: array [0..3] of string =('1001A', '1001B', '1001C', '1001D'); var index: integer; begin for index := Low(TypeArray) to High(TypeArray) do if SameText(TypeArray[index], aType) then Case index of 0 : //Do Something... 1 : //Do Something... 2 : //Do Something... 3 : //Do Something... . .
type TStringState=(s_normal,s_a,s_b); TArray=array[TStringState]of string;var arr:TArray; str:string; I:TStringState; begin str:=Edit1.Text; arr[s_normal]:='snormal'; arr[s_a]:='sa'; arr[s_b]:='sb'; for I :=low(TStringState) to high(TStringState) do begin if str=arr[I] then case I of s_normal:showmessage('snormal'); s_a:ShowMessage('sa'); s_b:showmessage('sb'); end; end;end;
设置变量,给它赋值: var i:integer; str:string; begin str:=edit1.Text; case i of 0:str:='this is a example'; 1:str:='delphi'; end; 仅供参考.
case stringindex(edit.text,[caselist1,caselist2,caselist3]) of
1:statement1;
2:statement2;
3:statement3;
end;
casseasd
stringindex()函数实现如下:
function stringindex(const searchstring:string;strlist:array of string):integer;
var
i:integer;
begin
result:=-1;
for i:=0 to high(strlist) do
if comparetext(searchstring,strlist[i])=0 then
begin
result:=i;
break;
end;
end;
case就可以根据返回值做相应的操作了
const
TypeArray: array [0..3] of string =('1001A', '1001B', '1001C', '1001D');
var
index: integer;
begin
for index := Low(TypeArray) to High(TypeArray) do
if SameText(TypeArray[index], aType) then
Case index of
0 : //Do Something...
1 : //Do Something...
2 : //Do Something...
3 : //Do Something...
.
.
TStringState=(s_normal,s_a,s_b);
TArray=array[TStringState]of string;var
arr:TArray;
str:string;
I:TStringState;
begin
str:=Edit1.Text;
arr[s_normal]:='snormal';
arr[s_a]:='sa';
arr[s_b]:='sb';
for I :=low(TStringState) to high(TStringState) do
begin
if str=arr[I] then
case I of
s_normal:showmessage('snormal');
s_a:ShowMessage('sa');
s_b:showmessage('sb');
end;
end;end;
var
i:integer;
str:string;
begin
str:=edit1.Text;
case i of
0:str:='this is a example';
1:str:='delphi';
end;
仅供参考.