Sierra C
Sierra C

Reputation: 305

Receive WM_COPYDATA messages on Firemonkey form?

I am in the process of porting a Windows VCL application to Windows FMX (Firemonkey) in Delphi XE7, and have been stuck on this one issue...

How do you receive messages such as WM_COPYDATA on a Firemonkey form?

I have procedure WMCopyData(var msg: TWMCopyData); message WM_COPYDATA; in the protected part of my form, but the message is never received. Identical code on VCL form works fine. I understand why it doesn't work (FMX doesnt use Windows message loops?), not sure of what to do about it.

Upvotes: 1

Views: 1049

Answers (1)

David Heffernan
David Heffernan

Reputation: 612854

FMX on Windows does indeed rely on the Windows message loop. But the architecture doesn't support message delivery using the message keyword.

In any case, your VCL code is a little flaky because it presumes that your form's window will not be re-created. It's perfectly plausible that the window will be re-created so using the form's window handle as a message recipient is a dubious practice.

The best way to work around that problem, and also to solve your FMX problem, is to create a window dedicated to the task of receiving these messages. If you control the window creation, then you can ensure that the window lives as long as you need it, and is not subject to VCL window re-creation.

On the Windows platform you can do this by calling AllocateHWnd from the System.Classes unit. Of course this is Windows specific, but then WM_COPYDATA is Windows specific so that's not going to be a concern for you.

Upvotes: 1

Related Questions