开发者

PostMessage / SendMessage in Cross-Platform Delphi?

For cross-platform development, I am not sure what is required to make Delphi code cross-platform which uses PostMessage and SendMessage calls for intra- and interprocess commuication, as there is little information about a new runtime library for Delphi.

On the web there are quite many Delphi code examples which uses the Windows message queue for programming tasks (开发者_开发问答for example in the area of thread communication), which might become useless for cross-platform developers.

How likely is it that there will be no emulation layer which maps old operating-specific message sending code to a cross-platform solution? Should application developers start now with reviews of existing code with new messaging implementations which are better suited for cross-platform operation?


PostMessage and SendMessage are Windows-specific - they are a part of the Windows API. If your program uses them then it is not cross-platform. You should probably rewrite the code that uses those functions.


Other operating system may have not a message queue at all. Windows specific code has to be isolated or removed to build cross-platoform applications. One of the reason they wrote the CLX library for Kylix is the VCL is so Windows-bound it can't be easily transformed into a cross-platform libray.


I suspect that you could implement your own Queue object, which could be implemented, in a platform specific manner. In Win32, it could wrap an underlying Win32 window handle, and in some other platform, some other resources could be consumed.

What if you start right now, by reducing your platform specific code, to certain units that encapsulate the functionality that you need. That means that you would need to avoid using PostMessage/SendMessage as a mechanism that you directly use.

To start with, imagine PostMessage, and SendMessage do not exist, and you need a way to create a queue. You could use sockets, for example, or named pipes, which exist on most platforms. You would need to write a bit more code, to do it this way.

On the QT libraries, they provide their own functionality to help application authors rewrite their C++ apps to use their functions instead of Win32 functions, so you could also try that approach. The QT function postEvent is an example of this. QT also provides signals and slots, and this is the more idiomatic way of doing notifications in their framework.

Perhaps the way of doing notifications in whatever new framework comes out with cross-platform Delphi might contain a whole new way of doing this. That's my hope.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜