组件数组

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

利用 Form  的Components属性,这个属性就是Form中全部的组件的数组,经过它来索引组件,显然这是不方数据结构

便的:spa

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;

显然这样仍是有局限性的。code

在DelphiXE 中咱们会发现 TComponentList 这样的数据结构,就是经过它咱们即可创建一个组件链表,它的父类orm

是TObjectList,这个也能够作组件链表。blog

var
  ComList : TComponentList;
begin
  ComList := TComponentList.Create;
  ComList.Add(lbl1);
  ComList.Add(lbl2);
  ComList.Add(lbl3);
  (ComList.Items[0] as TLabel).Caption := 'Hello';
end;