TIdNotify在Delphi Tokyo中已弃用

问题描述

我正在这样使用TIdNotify:

type
  TMsgNotify = class(TIdNotify)
  protected
    aMsgStr: string;
    procedure DoNotify; override;
  end;

procedure TMsgNotify.DoNotify;
begin
  // this runs in the main thread
  Form1.Log(aMsgStr); 
end;

procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
  try
    ...    
    if ARequestInfo.Command = 'POST' then
      begin
        //do Msg thread
        with TMsgNotify.Create do begin
          aMsgStr:='>> RawHTTP Command: ' + ARequestInfo.RawHTTPCommand;
          Notify;
          // Do not call Free(),TIdNotify will free itself when it is finished...
        end;
        ...
      end;
  finally
    ...
  end;
end;

在Embarcadero Delphi Tokyo中进行编译时,我收到此消息:

[dcc64警告] Unit1.pas(230):不推荐使用W1000符号“ TIdNotify”:“使用静态TThread.Queue()”

为新版本的Delphi重新编码此代码的正确方法是什么?

解决方法

TThread.Queue()与匿名过程一起使用,例如:

procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  aMsgStr: string;
begin
  try
    ...
    if ARequestInfo.Command = 'POST' then
    begin
      //do Msg thread
      aMsgStr := '>> RawHTTP Command: ' + ARequestInfo.RawHTTPCommand;
      TThread.Queue(nil,procedure
        begin
          // this runs in the main thread
          Log(aMsgStr);
        end
      );
      ...
    end;
  finally
    ...
  end;
end;

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...