如何在 Indy 中使用视觉控制? (德尔福)
我的服务器必须打印一些有关其工作的报告。如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
同样的规则,即不在除主线程之外的任何线程中修改 VCL 对象,在这里也有效。您不应更改 OnExecute 事件处理程序中的任何 VCL 控件,因为该代码将在 Indy 为每个连接生成的工作线程的上下文中运行。
如果您需要更改图形用户界面,请使用 Synchronize 或 Queue 方法来完成,或者使用自定义通知机制来通知主线程为您进行 GUI 修改。
如果要调用 Synchronize 或 Queue 方法,则必须将 TIdYarn 类型转换为 TIdYarnOfThread,后者派生自 TIdYarn 并使用线程实现它:
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: