组件数组

在Delphi中,早期的时候我们没办法建立 像这样的 array of TButton 的组件数组。我们的使用的方法或许是:

利用 Form  的Components属性,这个属性就是Form中所有的组件的数组,通过它来索引组件,显然这是不方

便的:

var
  Index : Integer;
begin
  For Index:=0 to ControlCount-1 do
  begin
    if Components[Index] is TLinkLabel then
    begin
      (Components[Index] As TLinkLabel).Caption:='hello';
    end
  end;
end;

显然这样还是有局限性的。

在DelphiXE 中我们会发现 TComponentList 这样的数据结构,就是通过它我们便可建立一个组件链表,它的父类

是TObjectList,这个也可以做组件链表。

var
  ComList : TComponentList;
begin
  ComList := TComponentList.Create;
  ComList.Add(lbl1);
  ComList.Add(lbl2);
  ComList.Add(lbl3);
  (ComList.Items[0] as TLabel).Caption := 'Hello';
end;
原文地址:https://www.cnblogs.com/wangmingshuo/p/3354693.html