不对啊,看看这个例子 The following example creates 20 edit boxes, using FindComponent with the edit box name to access each newly created edit box.procedure TForm1.Button1Click(Sender: TObject);var i: Integer; const NamePrefix = 'MyEdit'; begin for i := 1 to 20 do begin TEdit.Create(Self).Name := NamePrefix + IntToStr(i); with TEdit(FindComponent(NamePrefix + IntToStr(i))) do begin Left := 10; Top := i * 20; Parent := self; end; end; end; 用FindComponent可以实现对在form上动态创建控件的引用 我的控件是创建到gropebox上的,应该也这样引用 正在尝试:)
lbl:=GroupBox3.FindComponent('lblActive0') as Tlabel; 怎么在groupbox上还是找不到 cry~~~~~~~~
lbl:=self.FindComponent('lblActive0') as Tlabel; 终于找到了:) 看来GroupBox不是容器
我用FlatGroupbox竟然不是容器,我倒~~~~~~~~ 看来第三方控件用起来要小心
可以设置控件数组:var btn:array [1..20] of TSpeedButton; begin for i:= 1 to 20 do begin btn[i] := TSpeedButton.Create(groupbox1); btn[i].Parent := groupbox1; end; ... for i:= 1 to 20 do btn[i].free;
你不需要对:btn.name付值,当然你的btn要在public或private都可以(看你的自己的了)
直接用btn就可以了,btn.free也是必不可少的,哈哈。
The following example creates 20 edit boxes, using FindComponent with the edit box name to access each newly created edit box.procedure TForm1.Button1Click(Sender: TObject);var
i: Integer;
const
NamePrefix = 'MyEdit';
begin
for i := 1 to 20 do begin
TEdit.Create(Self).Name := NamePrefix + IntToStr(i);
with TEdit(FindComponent(NamePrefix + IntToStr(i))) do
begin
Left := 10;
Top := i * 20;
Parent := self;
end;
end;
end;
用FindComponent可以实现对在form上动态创建控件的引用
我的控件是创建到gropebox上的,应该也这样引用
正在尝试:)
怎么在groupbox上还是找不到
cry~~~~~~~~
终于找到了:)
看来GroupBox不是容器
看来第三方控件用起来要小心
begin
for i:= 1 to 20 do
begin
btn[i] := TSpeedButton.Create(groupbox1);
btn[i].Parent := groupbox1;
end;
...
for i:= 1 to 20 do
btn[i].free;