如何把一大堆按钮当作一维数组使用,下标是个变量的那种?

解决方案 »

  1.   

    楼上说得对
    动态创建按钮,将按钮的caption赋值为循环中的那个变量就ok了你说的下标是不是caption
      

  2.   

    下表就是数字了;
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls, StdCtrls;type
      TForm1 = class(TForm)
        TreeView1: TTreeView;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      aa:array of tbutton;implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      i:integer;
    begin
      setlength(aa,10);
      for i:=1 to 10 do
      begin
        aa[i]:=tbutton.Create(self);
        aa[i].Caption:=inttostr(i);
        aa[i].Parent:=form1;
        aa[i].Visible:=true;
        aa[i].Top:=i*10;
      end;
    end;end.