IdNotify:如何将参数传递给函数 [英] IdNotify : How to pass parameteres to function

查看:145
本文介绍了IdNotify:如何将参数传递给函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过长时间的努力后,我安装了带有lazarus的代码台风,我设法将IdSync单元添加到我的项目中.

I have code typhoon with lazarus installed after a long strugle I have managed to include the unit IdSync to my project.

如何从TIdNotify将参数传递给要在主线程中执行的函数?

How can I pass parameteres to a function that I want to execute in the main thread from TIdNotify ?

推荐答案

您必须重写TIdNotify.DoNotify()方法,然后才能传递所需的任何参数,例如:

You have to override the TIdNotify.DoNotify() method, then you can pass whatever parameters you want, eg:

type
  TMyNotify = class(TIdNotify)
  protected
    procedure DoNotify; override;
  end;

procedure TMyNotify.DoNotify;
begin
  SomeFunction(parameters);
end;

.

begin
  ...
  TMyNotify.Create.Notify;
  ...
end;

大概,您希望调用线程指定参数值,因此只需使其成为类的成员即可,例如:

Presumably, you want the calling thread to specify the parameter values, so just make them members of the class, eg:

type
  TMyNotify = class(TIdNotify)
  protected
    Param1: SomeType;
    Param2: SomeType;
    Param3: SomeType;
    procedure DoNotify; override;
  end;

procedure TMyNotify.DoNotify;
begin
  SomeFunction(Param1, Param2, Param2);
end;

.

begin
  ...
  with TMyNotify.Create do
  begin
    Param1 := ...;
    Param2 := ...;
    Param3 := ...
    Notify;
  end;
  ...
end;

这篇关于IdNotify:如何将参数传递给函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆