如果没有,有什么方法可以比较方便地像数组一样地操作一大批控件?

解决方案 »

  1.   

    type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        FButtonList: array[0..10] of TButton;
        procedure ButtonClick(Sender: TObject);
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.ButtonClick(Sender: TObject);
    begin
      ShowMessage(TButton(Sender).Name);
    end;procedure TForm1.FormCreate(Sender: TObject);
    var
      I: Integer;
    begin
      for I := Low(FButtonList) to High(FButtonList) do begin
        FButtonList[I] := TButton.Create(Self);
        FButtonList[I].Parent := Self;
        FButtonList[I].Top := I * (FButtonList[I].Height + 2);
        FButtonList[I].Name := Format('Button%d', [I]);
        FButtonList[I].Caption := FButtonList[I].Name;
        FButtonList[I].OnClick := ButtonClick;
      end;
    end;
      

  2.   

    for i:=0 to form1.componentcount-1 do
    begin
      form1.components[i]......
      
    end;
      

  3.   

    for i:=0 to form1.componentcount-1 do
    begin
      if form1.components[i].ClassName='TCheckBox' then
        //然后将同类控件放入TListBox
        //......
      
    end;
      

  4.   

    //然后将同类控件放入TStringList
      

  5.   

    这就是控件数组:
    btn:array [1..100] of Tbutton