传递函数而不是调用它(Delphi)

传递函数而不是调用它(Delphi),第1张

概述所以我在Delphi中有一个表单 TFrmMainForm = class(TForm, IFrmMainFormInterface) public procedure Display(Sender:TObject); end; 界面是 IFrmMainFormInterface = interface procedure Display(Sender:TObject);end 所以我在Delphi中有一个表单

TFrmMainForm = class(TForm,IFrmMainFormInterface)  public    procedure display(Sender:TObject); end;

界面是

IFrmMainFormInterface = interface  procedure display(Sender:TObject);end;

另一堂课

TMainFormviewmodel = class    strict private      fTimer : TTimer;      function GetonTimer : TNotifyEvent;      procedure SetonTimer(timerEvent : TNotifyEvent);    public      property OnTimer : TNotifyEvent read GetonTimer write SetonTimer;end;implementationfunction TMainFormviewmodel.GetonTimer : TNotifyEvent;begin    Result := fTimer.OnTimer;end;procedure TMainFormviewmodel.SetonTimer(timerEvent : TNotifyEvent);begin    fTimer.OnTimer := timerEvent;end;

我有一个Form MainForm的实例和视图模型类MainFormviewmodel

我想试试

MainFormviewmodel.OnTimer := IFrmMainFormInterface(MainForm).display

问题是这给我一个错误信息

Not enough actual parameters

我相信这是因为delphi试图调用显示功能而不是将其分配给OnTimer事件.我不知道如何解决这个问题,我尝试使用@运算符但没有成功.

编辑

我应该补充一点,MainForm在这个函数中被声明为

procedure Initialise<T:Class,IFrmMainFormInterface>(MainForm : T);
procedure TController.Initialise<T>(MainForm : T);begin    MainFormviewmodel.OnTimer := IFrmMainFormInterface(MainForm).display ;end;
解决方法
MainFormviewmodel.OnTimer := IFrmMainFormInterface(MainForm).display;

问题是您无法在此上下文中使用接口的方法. OnTimer事件是对象方法类型.它必须是对象或记录的方法.

总结

以上是内存溢出为你收集整理的传递函数而不是调用它(Delphi)全部内容,希望文章能够帮你解决传递函数而不是调用它(Delphi)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1265335.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存