L
larryle
Unregistered / Unconfirmed
GUEST, unregistred user!
编译下面代码的时候总是告诉我'Not enough actual parameters',就在
btnClose.onClick=listener.onNotifyEvent 这句这出错。
如果把 setListener(listener: IEventListener);改为
TForm1.setListener(listener: TControll);就没错。
我理解,问题可能出在TNotifyEvent的定义上,interface的函数和class中的函数即使定义完全一样,delphi也认为是不同的。
哪位能给个主意,使编译的时候不出错误(listener 类型还是IeventListener)?
谢谢
larry
=================================================================
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
IEventListener = interface
procedure onNotifyEvent(Sender: TObject);
end;
TControll = class(TInterfacedObject, IEventListener)
procedure onNotifyEvent(Sender: TObject);
end;
TForm1 = class(TForm)
btnClose: TButton;
private
{ Private declarations }
public
{ Public declarations }
procedure setListener(listener: IEventListener);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TControll.onNotifyEvent(Sender: TObject);
begin
if TButton(sender).caption = 'Close' then
else
end;
procedure TForm1.setListener(listener: IEventListener);
begin
btnClose.onClick := listener.onNotifyEvent
// 这出错
end;
end.
btnClose.onClick=listener.onNotifyEvent 这句这出错。
如果把 setListener(listener: IEventListener);改为
TForm1.setListener(listener: TControll);就没错。
我理解,问题可能出在TNotifyEvent的定义上,interface的函数和class中的函数即使定义完全一样,delphi也认为是不同的。
哪位能给个主意,使编译的时候不出错误(listener 类型还是IeventListener)?
谢谢
larry
=================================================================
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
IEventListener = interface
procedure onNotifyEvent(Sender: TObject);
end;
TControll = class(TInterfacedObject, IEventListener)
procedure onNotifyEvent(Sender: TObject);
end;
TForm1 = class(TForm)
btnClose: TButton;
private
{ Private declarations }
public
{ Public declarations }
procedure setListener(listener: IEventListener);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TControll.onNotifyEvent(Sender: TObject);
begin
if TButton(sender).caption = 'Close' then
else
end;
procedure TForm1.setListener(listener: IEventListener);
begin
btnClose.onClick := listener.onNotifyEvent
// 这出错
end;
end.