with TLabel.Create(Self) do begin Parent := self; Top := 100; Left := 100; Caption := 'Test; Visible := true; end;
循环是可以的, 但在声明的时候 var LB_1:TLabel; 这里是不能循环的。。
label类型的动态数组,是怎么声明的??? 哪位大哥指点下
var LB : array[1..n] of TLabel; for i:=1 to n do begin LB[i]:=TLabel.Create(Self); LB[i].Parent:=Form1; LB[i].Left:=100; LB[i].Top:=50+i*dy; LB[i].Caption:='label'+inttostr[i]; end;
楼上,你的代码是错误的,必须声明的是动态树组 A: array of Tlabel;
procedure TForm1.Button1Click(Sender: TObject); var A: array of Tlabel; i,j:integer; begin i:=strtoint(edit1.text); setlength(a,i); for j:=0 to i-1 do begin a[j]:=TLabel.Create(Self); a[j].Parent:=Form1; a[j].Left:=100; a[j].Top:=50+i*10; a[j].Caption:='label'+inttostr(j); end; end;
procedure TForm1.Button1Click(Sender: TObject); var A: array of Tlabel; i,j:integer; begin i:=strtoint(edit1.text); setlength(a,i); for j:=0 to i-1 do begin a[j]:=TLabel.Create(Self); a[j].Parent:=Form1; a[j].Left:=100; a[j].Top:=50+j*20; a[j].Caption:='label'+inttostr(j); end; end;
LB_1:TLabel;
LB_1:=TLabel.Create(Self);
LB_1.Parent:=Form1;
LB_1.Left:=100;
LB_1.Top:=100;
LB_1.Caption:='测试';
begin
Parent := self;
Top := 100;
Left := 100;
Caption := 'Test;
Visible := true;
end;
var
LB_1:TLabel; 这里是不能循环的。。
LB : array[1..n] of TLabel; for i:=1 to n do
begin
LB[i]:=TLabel.Create(Self);
LB[i].Parent:=Form1;
LB[i].Left:=100;
LB[i].Top:=50+i*dy;
LB[i].Caption:='label'+inttostr[i];
end;
A: array of Tlabel;
var
A: array of Tlabel;
i,j:integer;
begin
i:=strtoint(edit1.text);
setlength(a,i);
for j:=0 to i-1 do
begin
a[j]:=TLabel.Create(Self);
a[j].Parent:=Form1;
a[j].Left:=100;
a[j].Top:=50+i*10;
a[j].Caption:='label'+inttostr(j);
end;
end;
但,要生成10个动态的lebel即在edit1中输入10
程序只生成了 label2 和 label9,请问这是怎么会事啊???????
楼上的程序,如果我要生成10个动态的lebel即在edit1中输入10
程序只生成了 label9,也就是最后一项,请问这是怎么会事啊???????
var
A: array of Tlabel;
i,j:integer;
begin
i:=strtoint(edit1.text);
setlength(a,i);
for j:=0 to i-1 do
begin
a[j]:=TLabel.Create(Self);
a[j].Parent:=Form1;
a[j].Left:=100;
a[j].Top:=50+j*20;
a[j].Caption:='label'+inttostr(j);
end;
end;