怎么样手动添加一个事件???? 是这样的:我要给form1添加一个OoMouseDown 事件,比如:form1.OnMouseDown := MyMouseDown; //但这样报错了。请问MyMouseDown事件应该怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private { Private declarations } procedure MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); public { Public declarations } end;var Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);begin onMouseDown := mouseDown;end;procedure TForm1.mouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin//end;end. 同意idilentMyMouseDown应该和OnMouseDown是同一 Tprocedure 类型 OnMouseDown是TMouseEvent类型的,这样行吗? 打开Tform的创建代码看看就知道了。 你将procedure onmonusedown(sender:Tobject)的声明放在什么地方,应该在Tform1的定义中type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); //此处放MyOnMouseDown声明 private { Private declarations } //或此处放MyOnMouseDown声明 public //或此处放MyOnMouseDown声明 { Public declarations } end; unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) procedure onmonusedown(); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.onmonusedown();begin 事件驱动! end;procedure TForm1.mouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin//end;end. 其实就是动态创建一个控件然后给该对象的事件定义一个函数。该函数的参数与onmousedown的参数相同,/////////////////////////////////////////////////////////unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;type TForm1 = class(TForm) private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}end.//////////////////////////////////////////////////////////////unit Unit2;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm2 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } // myForm1: TForm1; procedure MyMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); public { Public declarations } end;var Form2: TForm2; //myForm1: Form1;implementationuses Unit1;{$R *.dfm}procedure TForm2.MyMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin ShowMessage('ok');end;procedure TForm2.Button1Click(Sender: TObject);var MyForm: TForm1;begin MyForm := TForm1.Create(nil); myForm.OnMouseDown := Form2.MyMouseDown; MyForm.ShowModal;end;end./////////////////////////////////////////////////////主窗体为form2,form1是手动创建的 关于SQL的query查询----很奇怪的问题!!!大虾指点!!! 怎样修改ACCESS里的字段名? 返回值问题 请问谁有小灵通的相关资料? 菜鸟问题,请各位高手指点一二吧! !!!建议:提问时在标题中注明与问题相关的“关键词语”!!! 请问谁知道哪里有dxdbgrid for delphi7下载? 关于中间层的应用? 我要delphi6.0和orecle做一个管理系统,不知道用什么方式连接数据库比较好 my win2000 server 设计学生分班程序的设计思想是什么 获取句柄后的问题
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private
{ Private declarations } procedure MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); public
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
onMouseDown := mouseDown;
end;procedure TForm1.mouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
//
end;end.
MyMouseDown应该和OnMouseDown是同一 Tprocedure 类型
应该在Tform1的定义中
type
TForm1 = class(TForm) procedure FormCreate(Sender: TObject); //此处放MyOnMouseDown声明
private
{ Private declarations }
//或此处放MyOnMouseDown声明
public
//或此处放MyOnMouseDown声明
{ Public declarations }
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm) procedure onmonusedown(); private
{ Private declarations } public
{ Public declarations }
end;var
Form1: TForm1;implementation
{$R *.dfm}procedure TForm1.onmonusedown();
begin
事件驱动!
end;procedure TForm1.mouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
//
end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}end.
//////////////////////////////////////////////////////////////
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
// myForm1: TForm1;
procedure MyMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
public
{ Public declarations }
end;var
Form2: TForm2; //myForm1: Form1;implementationuses Unit1;{$R *.dfm}procedure TForm2.MyMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ShowMessage('ok');
end;procedure TForm2.Button1Click(Sender: TObject);
var
MyForm: TForm1;
begin
MyForm := TForm1.Create(nil);
myForm.OnMouseDown := Form2.MyMouseDown;
MyForm.ShowModal;
end;end.
/////////////////////////////////////////////////////
主窗体为form2,form1是手动创建的