如何在 Indy 中使用视觉控制? (德尔福)

发布于 2024-10-04 20:54:15 字数 58 浏览 0 评论 0原文

我的服务器必须打印一些有关其工作的报告。如何在 OneEecute 事件中使用标签、编辑框等可视对象?

My server must print some reports about its work. How can I use visual objects such as labels, edit boxes in the OneEecute event?

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

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

发布评论

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

评论(1

影子的影子 2024-10-11 20:54:15

同样的规则,即不在除主线程之外的任何线程中修改 VCL 对象,在这里也有效。您不应更改 OnExecute 事件处理程序中的任何 VCL 控件,因为该代码将在 Indy 为每个连接生成的工作线程的上下文中运行。

如果您需要更改图形用户界面,请使用 Synchronize 或 Queue 方法来完成,或者使用自定义通知机制来通知主线程为您进行 GUI 修改。

如果要调用 Synchronize 或 Queue 方法,则必须将 TIdYarn 类型转换为 TIdYarnOfThread,后者派生自 TIdYarn 并使用线程实现它:

// 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);

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