用数组、TList、或者TObjectList保存对象列表,然后用循环对每一个实例进行操作:for i:=0 to Count-1 // or T[Object]List.Count-1 begin Objs[i]....// or TMyObject(TTObjectList.Items[i]).... end;
看看你到底相干什么.procedure TForm1.Button5Click(Sender: TObject); var I: Integer; begin for I := 0 to ComponentCount - 1 do begin if Components[I] is TButton then ShowMessage('Button ' + IntToStr(I)); end; end;
<B>To JGTM2000</B> 请问怎样把字符串转换为控件. 如: edit1:tedit; a:string; begin a:='edit1'; 能否已知a,而通过某种方法将a解释为edit1呢?
JGTM2000说的办法就是很好的一种模拟的解决方式,是真正的Delphi。
完全同意JGTM2000,不过D5的列表释放好像有点问题,老死机。
var
I: Integer;
begin
for I := 0 to ComponentCount - 1 do
begin
if Components[I] is TButton then
ShowMessage('Button ' + IntToStr(I));
end;
end;
请问怎样把字符串转换为控件.
如:
edit1:tedit;
a:string;
begin
a:='edit1';
能否已知a,而通过某种方法将a解释为edit1呢?