加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Delphi XE2:可以在VCL应用程序中实例化一个FireMonkey表单?

发布时间:2020-12-15 10:17:52 所属栏目:大数据 来源:网络整理
导读:在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 e
在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或HD效果。

解决方法

这是完全可能的,因为可以将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
07001 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;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读