德尔福XE2 : Possible to instantiate a FireMonkey Form in VCL application?

标签 delphi vcl delphi-xe2 firemonkey

在 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/

相关文章:

Delphi:从什么时候开始,接口(interface)引用不再在 with block 末尾释放?

delphi - 如何通过代码在组合框中分配文本自动选择索引?

DELPHI:泛型和多态性

delphi - 如何将非绑定(bind)列添加到 DevExpress 数据库 QuantumGrid

delphi - 在XE2中设置单位范围

delphi - 在FMX中更改任务管理器应用程序名称

c# - 我应该如何从 C# 调用这个 native dll 函数?

delphi - Delphi 中抽象错误的可能不明原因?

Delphi TreeView DestroyWnd/CreateWnd 慢

delphi - 找出 TGridPanel 中控件的位置