对于动态生成的控件如何对该控件的事件函数赋值??

lwglucky 2005-10-13 09:18:26
对于动态生成的控件如何对该控件的事件函数赋值????
...全文
107 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dapei_712 2005-10-14
  • 打赏
  • 举报
回复
不知道你的Delphi示什么版本的?
我的示5.0的,上面的一段代码,稍微修改后可以实现的:
uses
Windows, Messages, SysUtils{, Variants}, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
lwglucky 2005-10-14
  • 打赏
  • 举报
回复
问题是:
btn.OnClick := MyButtonClick; {MyButtonClick---是全局函数的时候会报错}
ccrun.com 2005-10-13
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure MyButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.MyButtonClick(Sender: TObject);
begin
ShowMessage('动态生成按钮的点击事件');
end;

procedure TForm1.Button1Click(Sender: TObject);
var
btn: TButton;
begin
btn := TButton.Create(Form1);
btn.Caption := '动态按钮';
btn.Parent := Form1;
btn.Left := 10;
btn.Top := 10;
btn.OnClick := MyButtonClick;
btn.Show;
end;

end.

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧