Delphi XE2: Possible to instantiate a FireMonkey Form in VCL application?
This is perfectly possible, since the FMX form can be assigned to a panel.
See this blog article for details:
Just create a new FireMonkey form (2D or 3D, doesn't matter) save it and then add it to your VCL application (just accept the warning). You can create your FMX form instance somewhere and just show it - no problem. But what if you want to create some nice control with animations or something and embed it into your existing VCL form? Well, put a TPanel on your VCL form and include the brandnew unit DSharp.Windows.FMXAdapter.pas after the Vcl.ExtCtrls. Then just create your FMX form somewhere and assign it to the new Form property of your Panel - and boom, there you go.
In fact, the FMXAdapter.pas code is very short:
procedure TPanel.Resize;
begin
inherited;
ResizeForm();
end;
procedure TPanel.ResizeForm;
begin
if Assigned(FForm) then
Platform.SetWindowRect(FForm, RectF(BorderWidth, BorderWidth,
ClientWidth + BorderWidth, ClientHeight + BorderWidth));
end;
procedure TPanel.SetForm(const AForm: TCommonCustomForm);
begin
FForm := AForm;
FForm.BorderIcons := [];
FForm.BorderStyle := TFmxFormBorderStyle.bsNone;
ResizeForm();
FForm.Visible := True;
Winapi.Windows.SetParent(FmxHandleToHWND(FForm.Handle), Handle);
end;
For a more modern approach try TFireMonkeyContainer
. It's an open-source VCL component you can place on a VCL form, and it can host / embed a FireMonkey form inside it.
A FMX form embedded in a VCL form using TFireMonkeyContainer
Details here: introduction article, and followup with some bugfixes and more features. Find a link to the Google Code page and source here.
It works with XE2 and above, including XE4+ (where FMX had some large changes.)
Disclaimer: this is my component. (I created it to solve this very problem.) It's MPL-licensed so can be freely used even in commercial apps. Hope it helps you and makes your life easier!