M
MicroZeng
Unregistered / Unconfirmed
GUEST, unregistred user!
我要在Form1上动态地生成TLabel控件, 然后释放掉,如下程序为什么不行?
会出错? 请大虾帮我查找原因. 或者有什么更好的方法? 谢谢!
procedure TForm1.BitBtn1Click(Sender: TObject);
var Label1 : TLabel;
begin
Label1 := TLabel.Create(Self);
with Label1 do
begin
Parent := Form1;
Caption := IntToStr(Random(700));
Left := Random(800);
Top := Random(600);
end;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
var i, j : integer;
begin
j := ComponentCount;
for i := 0 to j -1 do
begin
if Components.ClassType = TLabel then //<font color="RED">这里会出错!!</font>
begin
Components.Free;
end;
end;
end;
会出错? 请大虾帮我查找原因. 或者有什么更好的方法? 谢谢!
procedure TForm1.BitBtn1Click(Sender: TObject);
var Label1 : TLabel;
begin
Label1 := TLabel.Create(Self);
with Label1 do
begin
Parent := Form1;
Caption := IntToStr(Random(700));
Left := Random(800);
Top := Random(600);
end;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
var i, j : integer;
begin
j := ComponentCount;
for i := 0 to j -1 do
begin
if Components.ClassType = TLabel then //<font color="RED">这里会出错!!</font>
begin
Components.Free;
end;
end;
end;