在 Delphi XE2 之前,我们仅使用 VCL 来创建 GUI 应用程序。 Delphi XE2 指出:
Caution: FireMonkey (FMX) and the Visual Component Library (VCL) are not compatible and cannot be used in the same project or application. That is, an application must be exclusively one or the other, either FireMonkey or VCL. The incompatibility is caused by framework differences between FireMonkey (FMX) and VCL.
我的应用程序是一个使用运行时包构建的纯 VCL 应用程序。所有 VCL 表单都存储在运行时包中。如果我要创建一个 FireMonkey 表单并将其存储在包中,我是否有机会在运行时在我的 VCL 应用程序中实例化此 FireMonkey 表单?所以我可能会喜欢FireMonkey的3D或高清效果。
最佳答案
这是完全可能的,因为 FMX 表单可以分配给面板。
参见this blog article详情:
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.
事实上,FMXAdapter.pas代码非常短:
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;
关于德尔福XE2 : Possible to instantiate a FireMonkey Form in VCL application?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7315050/