Delphi中动态生成的button调用onclick怎么传递参数 15
//procedureTForm1.OnClick(Sender:TObject);procedureTForm1.OnClick(Sender:TObject;x:in...
//procedure TForm1.OnClick(Sender: TObject);
procedure TForm1.OnClick(Sender: TObject; x: integer); //我这样写有问题吗?如果有错在哪里?该怎么写?
begin
showmessage(inttostr(x));
end;
...
var
btn: TButton;
begin
btn := TButton.Create(self);
btn.OnClick := OnClick; //请问这里如何写一个参数给onClick
end; 展开
procedure TForm1.OnClick(Sender: TObject; x: integer); //我这样写有问题吗?如果有错在哪里?该怎么写?
begin
showmessage(inttostr(x));
end;
...
var
btn: TButton;
begin
btn := TButton.Create(self);
btn.OnClick := OnClick; //请问这里如何写一个参数给onClick
end; 展开
展开全部
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TButtonClick=procedure(sender:TObject) of Object;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDblClick(Sender: TObject);
private
{ Private declarations }
procedure myClickEvent(sender:TObject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
Unit2;
{$R *.dfm}
procedure TForm1.myClickEvent(sender: TObject);
begin
//write you code
end;
//第一种用法
procedure TForm1.FormCreate(Sender: TObject);
var
evt: TButtonClick;
begin
evt:=form2.Button1Click;
self.Button1.OnClick:=evt;
end;
//第二种用法
procedure TForm1.FormDblClick(Sender: TObject);
begin
self.Button1.OnClick:=self.myClickEvent;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TButtonClick=procedure(sender:TObject) of Object;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDblClick(Sender: TObject);
private
{ Private declarations }
procedure myClickEvent(sender:TObject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
Unit2;
{$R *.dfm}
procedure TForm1.myClickEvent(sender: TObject);
begin
//write you code
end;
//第一种用法
procedure TForm1.FormCreate(Sender: TObject);
var
evt: TButtonClick;
begin
evt:=form2.Button1Click;
self.Button1.OnClick:=evt;
end;
//第二种用法
procedure TForm1.FormDblClick(Sender: TObject);
begin
self.Button1.OnClick:=self.myClickEvent;
end;
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询