为什么tthread在DLL中不起作用?但是在VCL表单应用程序中有效
为什么此线程过程使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在普通的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()
orTThread.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 theTApplication(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.