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;
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;
还可以不设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;
1 TOBJECTLIST 2 TLIST 3 动态数组技术: TYPE TLABELARR = ARRAY OF TLABEL; 然后SETLENGTH
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;
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
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;
2 TLIST
3 动态数组技术: TYPE TLABELARR = ARRAY OF TLABEL;
然后SETLENGTH
newfang(传说中的MIC) 的方法也可以,在使用上可能更灵活些,没有代码不好评论。