Delphi XE2:可以在VCL应用程序中实例化一个FireMonkey表单? [英] Delphi XE2: Possible to instantiate a FireMonkey Form in VCL application?

查看:246
本文介绍了Delphi XE2:可以在VCL应用程序中实例化一个FireMonkey表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Delphi XE2之前,我们只有VCL才能创建GUI应用程序。 Delphi XE2指出:

Prior to Delphi XE2, we have VCL only to create GUI apps. Delphi XE2 states that:


注意:FireMonkey(FMX)和Visual Component Library(VCL)是
不兼容,不能用于同一个项目或
应用程序。也就是说,一个应用程序必须是唯一的一个或
其他,FireMonkey或VCL。不兼容性是由FireMonkey(FMX)和VCL之间的
框架差异引起的。

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效果。

My application is a pure VCL application that built with runtime packages. All VCL forms are stored in runtime package. If I am going to create a FireMonkey form and store in a package, do I have any chance to instantiate this FireMonkey form in my VCL application at runtime? So I may enjoy the 3D or HD effects of FireMonkey.

推荐答案

这是完全可能的,因为FMX表单可以分配给

This is perfectly possible, since the FMX form can be assigned to a panel.

请参阅这篇博客文章的详细信息:


只需创建一个新的FireMonkey表单(2D或3D,无关紧要)保存
然后将其添加到您的VCL应用程序(只接受警告)。你
可以在某处创建你的FMX表单实例,只显示它 - 没有
问题。但是,如果你想用
动画或者某些东西来创建一些很好的控件,并将它嵌入你现有的VCL表单呢?
嗯,把一个TPanel放在你的VCL表单上,并且包括brandeew单位
DSharp.Windows.FMXAdapter.pas 。然后只需创建
您的FMX表单,并将其分配给您的
面板的新Form表单属性,并在那里进行升级。

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代码非常简短:

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;

这篇关于Delphi XE2:可以在VCL应用程序中实例化一个FireMonkey表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆