RAD Studio XE2(Delphi XE2)FireMonkey (FMX)与VCL技术对比

  • A+
所属分类:[开发技巧]

    因为新的 Delphi XE2已经使用 firemonkey,这个与我们这些delphi老鸟常年使用的VCL还是有差别的,新的Xe2继续保存的以前的Unit模式和代码方式,新的FireMonkey 被给予的一个不错的后缀名.FMX

下面的是主要代码的对比:

VCL


unit MainUnitVCL; 
interface
uses  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,   Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type 
TFormVCL = class(TForm) private 
{ Private declarations }
public  
 { Public declarations }
 end; 
var
  FormVCL: TFormVCL; 
implementation
{$R *.dfm}
 end.
(Firemonkey)
unit MainUnitFM;
 
interface
 
uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs;
 
type
  TFormFM = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  FormFM: TFormFM;
 
implementation
 
{$R *.fmx}
 
end.

大家可能可以看到,主要的差别在于:窗体类名和条件编译指令

设计界面对比:

(VCL)

  

(Firemonkey)

 

Firemonkey的界面风格会与使用的OS一致,在win7下就会事win7的风格,OSX 风格在OSX 中

窗口properties设置对比:

VCL

(FireMonkey)

                                                                 

 

      FMX与VCL采用的是完全不同的架构,FMX属性会跟运行所在的平台的对应,不像VCL完全是基于windows控件包。

   软件设计时对比:

VCL

 

FireMonkey

 

软件运行时对比:

VCL

 

(Firemonkey)

 

源代码比较

vcl

unit MainUnitVCL;

  

interface

  

uses

  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

  

type

  TFormVCL = class(TForm)

    Button1: TButton;

    Memo1: TMemo;

    Label1: TLabel;

    Edit1: TEdit;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

  

var

  FormVCL: TFormVCL;

  

implementation

  

{$R *.dfm}

  

procedure TFormVCL.Button1Click(Sender: TObject);

begin

  Memo1.Lines.Add(Edit1.Text);

  Label1.Caption := IntToStr(Memo1.Lines.Count);

end;

 

(Firemonkey)

 

unit MainUnitFM;

  

interface

  

uses

  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,

  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Edit, FMX.Layouts,

  FMX.Memo;

  

type

  TFormFM = class(TForm)

    Button1: TButton;

    Memo1: TMemo;

    Label1: TLabel;

    Edit1: TEdit;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

  

var

  FormFM: TFormFM;

  

implementation

  

{$R *.fmx}

  

procedure TFormFM.Button1Click(Sender: TObject);

begin

  Memo1.Lines.Add(Edit1.Text);

  Label1.Text := IntToStr(Memo1.Lines.Count);

end;

  

end.

可以很明显的看到 Label1的内容属性已经变为Text不再是 Caption

Firemonkey支持多系统多平台的表现:

 

 

窗体源代码对比:

VCL

object FormVCL: TFormVCL

  Left = 0

  Top = 0

  Caption = 'FormVCL'

  ClientHeight = 337

  ClientWidth = 635

  Color = clBtnFace

  Font.Charset = DEFAULT_CHARSET

  Font.Color = clWindowText

  Font.Height = -11

  Font.Name = 'Tahoma'

  Font.Style = []

  OldCreateOrder = False

  PixelsPerInch = 96

  TextHeight = 13

  object Label1: TLabel

    Left = 8

    Top = 8

    Width = 31

    Height = 13

    Caption = 'Label1'

  end

  object Button1: TButton

    Left = 536

    Top = 294

    Width = 75

    Height = 25

    Caption = 'Button1'

    Default = True

    TabOrder = 0

    OnClick = Button1Click

  end

  object Memo1: TMemo

    Left = 8

    Top = 24

    Width = 498

    Height = 265

    Lines.Strings = (

      'Memo1')

    TabOrder = 1

  end

  object Edit1: TEdit

    Left = 8

    Top = 296

    Width = 498

    Height = 21

    TabOrder = 2

    Text = 'Edit1'

  end

end

 

Firemonkey

    

object FormFM: TFormFM

  BiDiMode = bdLeftToRight

  Caption = 'FormFM'

  ClientHeight = 400

  ClientWidth = 600

  Left = 0

  Top = 0

  Transparency = False

  Visible = False

  StyleLookup = 'backgroundstyle'

  object Button1: TButton

    Position.Point = '(496,363)'

    Width = 80.000000000000000000

    Height = 22.000000000000000000

    OnClick = Button1Click

    TabOrder = 1

    StaysPressed = False

    IsPressed = False

    Text = 'Button1'

    Default = True

  end

  object Memo1: TMemo

    Position.Point = '(8,24)'

    Width = 473.000000000000000000

    Height = 321.000000000000000000

    TabOrder = 10

    WordWrap = False

  end

  object Label1: TLabel

    Position.Point = '(8,8)'

    Width = 120.000000000000000000

    Height = 15.000000000000000000

    TabOrder = 11

    Text = 'Label1'

  end

  object Edit1: TEdit

    Position.Point = '(8,360)'

    Width = 473.000000000000000000

    Height = 22.000000000000000000

    TabOrder = 12

    ReadOnly = False

    Password = False

  end

end

可以看到,FM对坐标的定位都精确到了小数点的N位

Firemonkey GUI倾斜效果

 

要在VCL中要实现这样的效果,可能不是那么容易吧

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
广告也精彩
avatar
广告也精彩

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: