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.
如上,请问怎么写事件?
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.
如上,请问怎么写事件?
beginend;
mybutton.click := MyClick;
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;
[Error] Unit1.pas(36): Left side cannot be assigned to
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;
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;
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'
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;
hongss
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;