为什么tthread在DLL中不起作用?但是在VCL表单应用程序中有效

发布于 2025-01-29 09:40:37 字数 586 浏览 2 评论 0原文

为什么此线程过程使用tidtcpserver在DLL库中不起作用,但在VCL表单应用程序中起作用?

procedure TFormFpsSrv.Display(p_sender : String; p_message : string);
begin
  TThread.Queue(nil, procedure
                        begin
                          memo1.Lines.Add(getNow + ' | '
                           + p_sender + ' | ' + p_message);
                          end);
end;
procedure TFormFpsSrv.IdTCPServer1Connect(AContext: TIdContext);
var
    port        : Integer;
begin
     Display('Serveris',' | Prisijungta portas: '+IntToStr(port));
end;

Why does this thread procedure not work in a DLL library using TIdTCPServer, but it works in a VCL Form application?

procedure TFormFpsSrv.Display(p_sender : String; p_message : string);
begin
  TThread.Queue(nil, procedure
                        begin
                          memo1.Lines.Add(getNow + ' | '
                           + p_sender + ' | ' + p_message);
                          end);
end;
procedure TFormFpsSrv.IdTCPServer1Connect(AContext: TIdContext);
var
    port        : Integer;
begin
     Display('Serveris',' | Prisijungta portas: '+IntToStr(port));
end;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘逸的'云 2025-02-05 09:40:37

在普通的DLL中,DLL和EXE具有自己的RTL副本,它们并非彼此共享。因此,调用tthread.synchronize()或 tthread.queue()dll的代码中的默认情况下不起作用,因为背景中没有任何运行来处理处理DLL的要求。

DLL将必须导出一个函数,该函数调用 /code> 函数的RTL副本,然后EXE需要定期调用该功能,例如计时器或tapplication(events).onidle 事件。

如果您创建一个运行时软件包(BPL)而不是DLL,那么这不是问题,然后将您的BPL和EXE配置为boh使用RTL Runtime软件包,以便它们共享相同的RTL实例。

In a plain DLL, the DLL and EXE have their own copies of the RTL, which are not shared with each other. As such, calling TThread.Synchronize() or TThread.Queue() in the DLL's code will not work by default, as there is nothing running in the background to process the DLL's requests.

The DLL will have to export a function that calls the CheckSynchronize() function for its copy of the RTL, and then the EXE will need to call that exported function periodically, such as in a timer, or in the TApplication(Events).OnIdle event.

This is not a problem if you create a Runtime Package (BPL) instead of a DLL, and then configure your BPL and EXE to boh use the rtl runtime package so that they share the same RTL instance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文