还可以不设TLabel类型变量
procedure TForm1.Button1Click(Sender: TObject);
var
count,i:integer;//count记录你要生成多少个label
begin
count := 100;
for i:=0 to count-1 do
with TLabel.Create(NIL) do
begin
Parent:=Form1;
Caption:='Label'+IntToStr(i);
Top:=i*2;
left := i*2;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
aLabel:array of TLabel;//一个关于tlabel的动态数组
count,i:integer;//count记录你要生成多少个label
begin
count := 100;
setlength(alabel,count);
for i:=0 to count-1 do
begin
aLabel[i]:=TLabel.Create(nil);
aLabel[i].Parent:=Form1;
aLabel[i].Caption:='Label'+IntToStr(i);
aLabel[i].Top:=i*2;
aleble[i].left := i*2;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var aLabel:TLabel;
i:integer;
begin
for i:=1 to 10 do
begin
aLabel:=TLabel.Create(self);
aLabel.Parent:=Form1;
aLabel.Caption:='Label'+IntToStr(i);
aLabel.Top:=i*30;
aLabel.Show;
end;
end;