var s : array of label i: integer; begin setlength(s,strtoint(edit1.text)); for i:= 0 to high(s) -1 do beign s[i] := TLabel.create(self); s[i].caption = 'jhj'; end; end;
label中不能显示jhj,是不是数组定义有问题
数组应定义为s:array of Tlable;而且主程序里应加入s[i].parent:=Form1;s[i].show;的语句,具体如下:procedure TForm1.Button1Click(Sender: TObject); const atop=20; var s : array of Tlabel ; i: integer; begin setlength(s,strtoint(edit1.text)); for i:= 0 to high(s) do begin s[i] := TLabel.create(self); s[i].caption := 'jhj'; s[i].parent:=Form1; s[i].Top:=i*atop; s[i].Show; end; end;
i: integer;
begin
setlength(s,strtoint(edit1.text));
for i:= 0 to high(s) -1 do
beign
s[i] := TLabel.create(self);
s[i].caption = 'jhj'; end;
end;
const atop=20;
var
s : array of Tlabel ;
i: integer;
begin
setlength(s,strtoint(edit1.text));
for i:= 0 to high(s) do
begin
s[i] := TLabel.create(self);
s[i].caption := 'jhj';
s[i].parent:=Form1;
s[i].Top:=i*atop;
s[i].Show; end;
end;