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

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

问题描述

在 Delphi XE2 之前,我们只有 VCL 来创建 GUI 应用程序.Delphi XE2 声明:

<块引用>

注意:FireMonkey (FMX) 和可视化组件库 (VCL) 是不兼容,不能在同一个项目中使用或应用.也就是说,一个应用程序必须是唯一的一个或其他,FireMonkey 或 VCL.不兼容是由FireMonkey (FMX) 和 VCL 之间的框架差异.

我的应用程序是一个使用运行时包构建的纯 VCL 应用程序.所有 VCL 表单都存储在运行时包中.如果我要创建一个 FireMonkey 表单并存储在一个包中,我是否有机会在运行时在我的 VCL 应用程序中实例化这个 FireMonkey 表单?所以我可以享受 FireMonkey 的 3D 或 HD 效果.

解决方案

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

查看这篇博客文章了解详情:><块引用>

只需创建一个新的 FireMonkey 表单(2D 或 3D,无所谓)保存它然后将其添加到您的 VCL 应用程序中(只需接受警告).你可以在某处创建您的 FMX 表单实例并显示它 - 不问题.但是如果你想创建一些不错的控件怎么办动画或其他东西并将其嵌入到您现有的 VCL 表单中?好吧,在你的 VCL 表格上放一个 TPanel 并包括全新的单元DSharp.Windows.FMXAdapter.pas 之后Vcl.ExtCtrls.然后只需创建您的 FMX 表单某处并将其分配给您的新表单属性面板 - 和繁荣,你去.

其实FMXAdapter.pas的代码很短:

procedure TPanel.Resize;开始遗传;ResizeForm();结尾;过程TPanel.ResizeForm;开始如果已分配(FForm)然后Platform.SetWindowRect(FForm, RectF(BorderWidth, BorderWidth,ClientWidth + BorderWidth, ClientHeight + BorderWidth));结尾;过程 TPanel.SetForm(const AForm: TCommonCustomForm);开始FForm := AForm;FForm.BorderIcons := [];FForm.BorderStyle := TFmxFormBorderStyle.bsNone;ResizeForm();FForm.Visible := True;Winapi.Windows.SetParent(FmxHandleToHWND(FForm.Handle), Handle);结尾;

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

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.

My application is a pure VCL application that is built with runtime packages. All VCL forms are stored in a 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.

解决方案

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;

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

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