如何在不创建Windows句柄的情况下将消息传递到TApartmentThread实例 [英] How to pass message to TApartmentThread Instance without creating Windows handle

查看:102
本文介绍了如何在不创建Windows句柄的情况下将消息传递到TApartmentThread实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将数据从DataSnap自动化服务器的主应用程序发布到为服务客户端而创建的RemoteDataModule实例中.

I wish to be able to post messages from the main application of a DataSnap automation server to the RemoteDataModule instances created to service clients.

我从其他论坛整体上了解,例如:

I understand from other forum entires, such as:

Delphi多线程消息循环

可以在线程中处理消息,而无需为此创建Windows句柄;使用PostThreadMessage发布的邮件.

That messages can be handled in threads without the need to create a Windows handle for the purpose; messages posted with PostThreadMessage.

但是,DataSnap TComponentFactory为每个RemoteDataModule创建一个TApartmentThread实例,并且它的Execute方法已经处理了消息:

However the DataSnap TComponentFactory creates a TApartmentThread instance for each RemoteDataModule, and it's Execute method already processes messages:

    while GetMessage(msg, 0, 0, 0) do
    begin
      DispatchMessage(msg);
      Unk._AddRef;
      if Unk._Release = 1 then break;
    end;

我想让它处理我的任何自定义消息,将意味着重写TApartmentThread Execute方法.

I imagine to get this to process any custom message of mine, would mean re-writing the TApartmentThread Execute method.

我已经确认,使用此处描述的技术可以创建一个窗口句柄来处理RemoteDataModule实例中的消息:

I have confirmed that creating a window handle to process messages in a RemoteDataModule instance works using the technique described here:

http://delphi.about.com/od/windowsshellapi/a/receive-windows-messages-in-custom-delphi-class-nonwindowed-control.htm

这使用了AllocateHWnd,由于其他人的工作,它可以成为线程安全的:

This uses AllocateHWnd, which can be made thread-safe thanks to the work of others:

如何使AllocateHwnd线程安全?

尽管这提供了解决方案,但我想问一下;有推荐的替代方法吗?

Although this presents a solution, I would like to ask; is there a recommended alternative approach?

推荐答案

看来,在TApartmentThread实例中处理自定义消息的唯一其他方法是重写Execute方法.

It would appear that the only other means of processing custom messages in a TApartmentThread instance would be to rewrite the Execute method.

这篇关于如何在不创建Windows句柄的情况下将消息传递到TApartmentThread实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆