IdNotify : How to pass parameteres to function

扶醉桌前 提交于 2019-12-11 13:53:35

问题


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

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


回答1:


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;


来源:https://stackoverflow.com/questions/13614325/idnotify-how-to-pass-parameteres-to-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!