Converting from VCL to FireMonkey
Go Up to FireMonkey Applications Guide
Differences Between VCL and FireMonkey Applications
The VCL (Visual Component Library) supports only Windows-based development—both the Win32 and the Win64 platforms. FireMonkey components, on the other hand, have been customized for use on all the supported platforms, including the OS X (Mac) platform.
FireMonkey is somewhat similar to the VCL library; FireMonkey and VCL share ancestry from TObject to TComponent, but they diverge beyond TComponent. If you are familiar with the VCL, some of the classes, components, controls, and functions in FireMonkey will be familiar. However, FireMonkey is a new framework that offers vector-based dynamic controls, and other features that the VCL does not offer. For example, FireMonkey has sophisticated 2D and 3D graphics, and special effects such as filters.
Migrating VCL Applications to FireMonkey
Although there is no direct migration path between the VCL and FireMonkey, you can convert an existing VCL application by creating a new HD FireMonkey Application, then modifying-cutting-pasting the existing VCL application, essentially refactoring the VCL application so that it is a FireMonkey application, which can run cross-platform.
Using the Mida Converter to Convert a VCL Application to FireMonkey
The Mida Converter is a third-party product that automates some aspects of converting VCL controls into FireMonkey controls. Mida installs as a plug-in to the Tools menu in the RAD Studio IDE.
Several versions of Mida are available:
- The free version of Mida migrates standard VCL controls and LiveBindings.
- For the free version, see http://cc.embarcadero.com/item/28943
- The Mida Pro and Mida Studio versions offer enhanced functionality, such as conversion of custom controls and images.
The Mida pack enables support for button images like the VCL TBitBtn component.
The Mida home page offers more information, including blogs, FAQs, and product orders: http://www.midaconverter.com/
Commonly Encountered Differences
Although FMX is designed to have some superficial similarity with VCL, numerous small differences can trip up someone that is familiar with VCL. These include, in no particular order:
- Standard Controls: Standard VCL controls are in the Vcl.StdCtrls unit, while equivalent FireMonkey controls are in FMX.Controls. Both frameworks have extra controls in an ExtCtrls unit (FMX.ExtCtrls and Vcl.ExtCtrls), but with no overlap between the two frameworks.
- In VCL, the position of a control is expressed by its Top and Left properties.
- In FireMonkey. controls use a Position of type TPosition with nested X and Y properties. 3D controls' Position property is an instance of TPosition3D, with an additional Z coordinate. For size, FireMonkey uses Width and Height (and Depth for 3D controls).
- Text: The text that appears in a FireMonkey label is its Text, not its Caption (as in VCL).
- Font Sizes:
- In FireMonkey, font sizes are expressed in device-independent pixels (DIPs), 96 per logical inch.
- In VCL, font sizes are expressed in points, 72 per logical inch.
- Therefore, text using the same Font.Size is smaller in FireMonkey.
- Check Boxes: In FireMonkey, check boxes should use the OnChange event to react to checked-state changes instead of OnClick. The property that reflects that state is IsChecked, not Checked as in VCL.
- Colors: FireMonkey colors have an alpha (opacity) component in addition to RGB. Colors are represented by system types TAlphaColor and TAlphaColorRec. FireMonkey color constants are in FMX.Types and prefixed with "cla" instead of "cl". Also see Colors in VCL.
- TPanel can be used in FireMonkey to achieve the same effect as the VCL TRadioGroup.
- Child-Parent Relationship: In VCL, objects parenting other components can be done only through TForms, TFrames, TPanels and Data Modules. In FireMonkey, you can parent any object to anything else, and this relationship can be easily established in the Structure View.
- A TMaskEdit or a TEdit in VCL can be implemented in FireMonkey using a TEdit and its Password property.
- Events: The VCL events OnDrawDataCell or OnDrawColumnCell can be replaced in FireMonkey with TStringGrid with LiveBindings.
- Constants: Constants like modal results and virtual key codes have moved from Vcl.Controls to System.UITypes.