如新建一Button
那么
声明方法
procedure MyClick(Sender: TObject);Button.OnClick:=MyClick你看下DFM文件就会明白!

解决方案 »

  1.   

    不可能不行!估计你是不知道在哪声明!这样吧,顺你的意
    Button.OnClick:=Self.MyClick;
    还有你的方法代码应该是
    procedure MyClick(Sender: TObject);
    begin
    ...
    end;
    如果是在窗体类中声明的
    应该是
    procedure Form1.MyClick(Sender: TObject);
    begin
    ...
    end;
    还要保证参数和控件方法的一致!
    叫你看看DFM文件中的做法!
      

  2.   


    button.Parent := Form2 ;
    button.name := "button";
    button.onclick:= myclick;procedure Form2.MyClick(Sender: TObject);
    begin
    ShowMessage(ok);
    end;
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
    bt:tbutton;
    begin
    bt:=tbutton.Create(self);
      with bt do
      begin
      parent:=form1;
      left:=31;
      top:=21;
      caption:='sfs';
      onclick:=my;
      end;
    end;procedure my(Sender: TObject);
    begin
    showmessage('sdf');
    end;end.
    错在哪里?
      

  4.   

    咳!错了!
    procedure my(Sender: TObject);没声明!unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      procedure my(Sender: TObject);implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
    bt:tbutton;
    begin
    bt:=tbutton.Create(self);
      with bt do
      begin
      parent:=form1;
      left:=31;
      top:=21;
      caption:='sfs';
      onclick:=my;
      end;
    end;procedure my(Sender: TObject);
    begin
    showmessage('sdf');
    end;end.
      

  5.   

    或者:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        procedure my(Sender: TObject);
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
    bt:tbutton;
    begin
    bt:=tbutton.Create(self);
      with bt do
      begin
      parent:=form1;
      left:=31;
      top:=21;
      caption:='sfs';
      onclick:=my;
      end;
    end;procedure TForm1.my(Sender: TObject);
    begin
    showmessage('sdf');
    end;end.
      

  6.   

    可以?
    我的是delphi6.0
    请把编译通过的代码发到我的信箱里。
    [email protected]
    谢谢