if 'yes' in ['word','pos','people','char'] then showmessage('在里面') else showmessage('不在里面');
if 'yes' in ['word';'pos';'people';'char'] then showmessage('在里面') else showmessage('不在里面'); 编译不通过,提示"ordinal type required"
//写个函数吧 function ins(s:string;sa:array of string;n:integer) :boolean; //设数组下标从0开始,并且为整型 var i:integer; begin result:=false; for i:=0 to n-1 do if s =sa[i] then begin result:=true; break; end; end;procedure TForm1.Button1Click(Sender: TObject); var sa:array [0..3] of string; begin inherited; sa[0]:='aa'; sa[1]:='bb'; sa[2]:='cc'; sa[3]:='dd'; if ins('ee',sa,4) then showmessage('1') else showmessage('0'); if ins('dd',sa,4) then showmessage('1') else showmessage('0'); end;
showmessage('在里面')
else
showmessage('不在里面');
showmessage('在里面')
else
showmessage('不在里面');
编译不通过,提示"ordinal type required"
function ins(s:string;sa:array of string;n:integer) :boolean;
//设数组下标从0开始,并且为整型
var i:integer;
begin
result:=false;
for i:=0 to n-1 do
if s =sa[i] then
begin
result:=true;
break;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
sa:array [0..3] of string;
begin
inherited;
sa[0]:='aa';
sa[1]:='bb';
sa[2]:='cc';
sa[3]:='dd';
if ins('ee',sa,4) then showmessage('1') else showmessage('0');
if ins('dd',sa,4) then showmessage('1') else showmessage('0');
end;