这条语句为何出错?(0分)

  • 主题发起人 主题发起人 awfigsk
  • 开始时间 开始时间
A

awfigsk

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button6Click(Sender: TObject);
var
i:integer;
typeStr:string;
procedure whathaveIGot(a:array of const);
begin
for i:=Low(a) to high(a) do
begin
[red]showmessage('A['+inttostr(i)+']的数据类型为:'+inttostr(a.vtype));[/red]
case a.vtype of
vtInteger :TypeStr:='Integer';
vtBoolean :TypeStr:='Boolean';
vtChar :TypeStr:='Char';
vtExtended:TypeStr:='Extended';
vtString :TypeStr:='String';
vtPointer :TypeStr:='Pointer';
vtPChar :TypeStr:='pChar';
vtObject :TypeStr:='Object';
vtClass :TypeStr:='Class';
vtWideChar:TypeStr:='WideChar';
vtPWidechar:TypeStr:='PWideChar';
vtAnsiString:TypeStr:='AnsiString';
vtCurrency:TypeStr:='Currency';
vtVariant :TypeStr:='Variant';
vtInterface:TypeStr:='Interface';
vtWideString:TypeStr:='WideString';
vtInt64 :TypeStr:='Int64';
end;
showmessage(format('Array item %d is a %s',[i,TypeStr]));
end;
begin
WhatHaveIGot(['Tabasco',90,5.6,@whathaveIGot,3.14159,True,'s']);
end;
红色这条语句错在哪里呢?错误提示如下:
[Error] main.pas(119): For loop control variable must be simple local variable
 
就是说循环变量必须是最内层的局部变量
 
像这个程序如何修改呢?(不好意思,我是名初学者,还请多多指点!,谢谢!)
 
procedure TForm1.Button6Click(Sender: TObject);
var
typeStr:string;
procedure whathaveIGot(a:array of const);
var
i:integer;
begin
for i:=Low(a) to high(a) do
begin
showmessage('A['+inttostr(i)+']的数据类型为:'+inttostr(a.vtype));
case a.vtype of
vtInteger :TypeStr:='Integer';
vtBoolean :TypeStr:='Boolean';
vtChar :TypeStr:='Char';
vtExtended:TypeStr:='Extended';
vtString :TypeStr:='String';
vtPointer :TypeStr:='Pointer';
vtPChar :TypeStr:='pChar';
vtObject :TypeStr:='Object';
vtClass :TypeStr:='Class';
vtWideChar:TypeStr:='WideChar';
vtPWidechar:TypeStr:='PWideChar';
vtAnsiString:TypeStr:='AnsiString';
vtCurrency:TypeStr:='Currency';
vtVariant :TypeStr:='Variant';
vtInterface:TypeStr:='Interface';
vtWideString:TypeStr:='WideString';
vtInt64 :TypeStr:='Int64';
end;
showmessage(format('Array item %d is a %s',[i,TypeStr]));
end;
end;
begin
WhatHaveIGot(['Tabasco',90,5.6,@whathaveIGot,3.14159,True,'s']);
end;

 
这样写
procedure TForm1.Button6Click(Sender: TObject);
var
typeStr:string;

procedure whathaveIGot(a:array of const);
var
i:integer;
begin
...
end;
begin
...
end
 
可以将typestr:string也写进 whathaveIGot该过程吗?
 
十分感谢各位大侠,是我的错误,程序中少写了一个end;.谢谢!
 
后退
顶部