此Button是动态产生的!
谢谢!!!

解决方案 »

  1.   

    http://expert.csdn.net/Expert/topic/2898/2898828.xml?temp=.5325434
    功能类似,参照其试一试
      

  2.   

    to  leeky():此Button是动态产生的!所以其属性都是动态的,怎么赋值给变量?
      

  3.   


    在DFW里找到:在Button的事件里的话:
    (Sender as TButton).Caption;
    (Sender as TButton).Name
      

  4.   

    // Unit1中的代码type
      TForm1 = class(TForm)
      private
        { Private declarations }
      public
        { Public declarations }
        procedure ButtonClick(Sender: TObject);
      end;procedure TForm1.ButtonClick(Sender: TObject); // 动态按钮的OnClick事件
    begin
      Form2.ShowForm(Sender);
    end;procedure TForm1.Button6Click(Sender: TObject);  // 通过这个过程来动态创建按钮
    var
      Button: TButton;
    begin
      Button := TButton.Create(Self);
      Button.Parent := Self;
      Button.Caption := '动态创建按钮';
      Button.OnClick := ButtonClick;  // 定义OnClick事件
      // Button.Free
    end;--------------------------------------------
    // Unit2中的代码type
      TForm2 = class(TForm)
      private
        { Private declarations }
      public
        { Public declarations }
        procedure ShowForm(Sender: TObject);
      end;var
      Form2: TForm2;implementation{$R *.dfm}{ TForm2 }procedure TForm2.ShowForm(Sender: TObject);
    begin
      if Sender is TButton then  // 使用TButton时候需要引用 StdCtrls 单元
        ShowMessage(TButton(Sender).Caption);
      Show;
    end;
      

  5.   

    procedure TForm2.ShowForm(Sender: TObject);
    begin
      if Sender is TButton then  // 使用TButton时候需要引用 StdCtrls 单元
      begin
        ShowMessage(TButton(Sender).Caption);  // 得到 Catpion
        ShowMessage(TButton(Sender).Name);    // 得到 Name
      end;
      Show;
    end;// Unit1 对应 Form1; Unit2 对应 Form2。