开发者

How to use visual controls in Indy? (Delphi)

My server must print some reports about its work. 开发者_运维技巧How can I use visual objects such as labels, edit boxes in the OneEecute event?


The same rule, for not modifying VCL objects in any thread except main thread, is valid here too. You should not change any of VCL controls in OnExecute event-handler, because that code will be run in the context of a worker thread spawn by Indy for every connection.

If you need to change graphical user interface, do it using Synchronize or Queue methods, or use a custom notification mechanism for notifying the main thread to do the GUI modification for you.

If you want to call Synchronize or Queue methods, you have to type-cast TIdYarn to TIdYarnOfThread which derives from TIdYarn and implements it with threads:

// Calling MyMethod using Synchornize inside TIdTcpServer.OnExecute event-handler   
TIdYarnOfThread(AContext.Yarn).Thread.Synchronize(MyMethod);


// Calling MyMethod using Queue inside TIdTcpServer.OnExecute event-handler  
TIdYarnOfThread(AContext.Yarn).Thread.Queue(MyMethod);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜