问题描述
我希望能够将数据从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:
可以在线程中处理消息,而无需为此创建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:
这使用了AllocateHWnd,由于其他人的工作,它可以成为线程安全的:
This uses AllocateHWnd, which can be made thread-safe thanks to the work of others:
尽管这提供了解决方案,但我想问一下;有推荐的替代方法吗?
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实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!