unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons;
TYPE
    NEWbutton =  class(TSpeedButton)
end;type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    NEWbutton :    TSpeedButton;
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
 NEWbutton:= TSpeedButton.Create(self);
 NEWbutton.Parent:=self;
 NEWbutton.SetBounds(180,72,73,33);
 NEWbutton.Caption:='OPEN';
end;end.
如上,请问怎么写事件?

解决方案 »

  1.   

    procedure MyClick(Sender:TObject);
    beginend;
    mybutton.click := MyClick;
      

  2.   

    mybutton.click := MyClick;写在那儿?
      

  3.   

    procedure MyClick(Sender:TObject);
    begin
      showmessage('click');
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
     NEWbutton:= TSpeedButton.Create(self);
     NEWbutton.Parent:=self;
     NEWbutton.SetBounds(180,72,73,33);
     NEWbutton.Caption:='OPEN';
     newbttion.click := MyClick;
    end;
      

  4.   

    报错
          
           [Error] Unit1.pas(36): Left side cannot be assigned to  
      

  5.   

    procedure MyClick(Sender:TObject);
    begin
      showmessage('click');
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
     NEWbutton:= TSpeedButton.Create(self);
     NEWbutton.Parent:=self;
     NEWbutton.SetBounds(180,72,73,33);
     NEWbutton.Caption:='OPEN';
     newbttion.OnClick := MyClick;
    end;
      

  6.   

    呃。。应该是procedure MyClick(Sender:TObject);
    begin
      showmessage('click');
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
     NEWbutton:= TSpeedButton.Create(self);
     NEWbutton.Parent:=self;
     NEWbutton.SetBounds(180,72,73,33);
     NEWbutton.Caption:='OPEN';
     NEWbutton.OnClick := MyClick;
    end;
      

  7.   

    [Error] Unit1.pas(36): Incompatible types: 'method pointer and regular procedure'
      

  8.   


    unit Unit1;
    interface
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Buttons;
    TYPE
        NEWbutton =  class(TSpeedButton)end;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        NEWbutton :    TSpeedButton;
      public
        { Public declarations }
      end;
    var
      Form1: TForm1;
    implementation
    {$R *.dfm}procedure MyClick(Sender:TObject);
    begin
      showmessage('click');
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
     NEWbutton:= TSpeedButton.Create(self);
     NEWbutton.Parent:=self;
     NEWbutton.SetBounds(180,72,73,33);
     NEWbutton.Caption:='OPEN';
     NEWbutton.onclick:=MyClick;end;
    end.为什么?
    [Error] Unit1.pas(36): Incompatible types: 'method pointer and regular procedure'
      

  9.   



      private
        NewButton: TBitBtn;
        procedure MyClick(Sender: TObject);
        { Private declarations }
      public
        { Public declarations }
      end;Procedure TForm1.MyClick(Sender: TObject);
    begin
      ShowMessage('Hello World');
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
     NEWbutton:= TSpeedButton.Create(self);
     NEWbutton.Parent:=self;
     NEWbutton.SetBounds(180,72,73,33);
     NEWbutton.Caption:='OPEN';
     NEWbutton.OnClick := MyClick;
    end;
      

  10.   

    能用了,谢谢
      
      hongss
      

  11.   

    procedure TForm1.btn3Click(Sender: TObject);
    begin
      NewBtn := TButton.Create(Self);
      with NewBtn  do
      begin
        Parent := Self;
        Left := 10;
        Top := 10;
        Caption := 'New Button';
        OnClick := MyClick;
      end;
    end;procedure TForm1.MyClick(Sender: TObject);
    begin
      ShowMessage('new button Ok');
    end;