J
jshyhzj
Unregistered / Unconfirmed
GUEST, unregistred user!
事件连接到其它类问题,希望熟悉DELPHI对象模型的富翁指导
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button2Click(Sender: TObject);
end;
TTest = class
public
procedure TestClick(Sender: TObject);
procedure toButton1OnClick;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
var
Test : TTest;
begin
Test := TTest.Create
//加不加此行Button1.Click反应不同!
Test.toButton1OnClick;
end;
procedure TTest.TestClick(Sender: TObject);
begin
showmessage(self.ClassName);
end;
procedure TTest.toButton1OnClick;
begin
Form1.Button1.OnClick := self.TestClick;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button2Click(Sender: TObject);
end;
TTest = class
public
procedure TestClick(Sender: TObject);
procedure toButton1OnClick;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
var
Test : TTest;
begin
Test := TTest.Create
//加不加此行Button1.Click反应不同!
Test.toButton1OnClick;
end;
procedure TTest.TestClick(Sender: TObject);
begin
showmessage(self.ClassName);
end;
procedure TTest.toButton1OnClick;
begin
Form1.Button1.OnClick := self.TestClick;
end;
end.