IdNotify : How to pass parameteres to function

2019-07-26 22:45发布

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 ?

标签: indy lazarus
1条回答
聊天终结者
2楼-- · 2019-07-26 23:10

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;
查看更多
登录 后发表回答