【发布时间】:2015-03-09 09:45:45
【问题描述】:
我的程序运行时创建的对象有问题
首先我创建 n 个对象(假设 n := 3)
for i:=0 to n-1 do
begin
With TGauge.Create(Form1) do
begin
Parent := Form1; // this is important
Left := 20; // X coordinate
Top := 20+i*45; // Y coordinate
Width := 250;
Height := 20;
Kind := gkHorizontalBar;
Name := 'MyGauge'+IntToStr(i);
//....
Visible := True;
end;
end;
这 3 个对象已创建并在表单中可见。现在我想改变它的属性,但是每当我尝试访问这些创建的对象时,我只会得到 p>
EAccessViolation
例如,当我尝试获取一个对象的名称时
g := Form1.FindComponent('MyGauge0') as TGauge;
Form1.Label1.Caption:=g.Name;
【问题讨论】:
-
最好将它们的引用存储到一个数组中,或者一个类似集合的列表中。
-
对于 n=3,你有 3 个对象,而不是 4 个。
-
@Inspired 感谢您的通知。只是拼写错误
-
“这很重要”我认为你的代码所有都很重要:-)
标签: delphi reference runtime components delphi-7