Delphi XE2: Is there a predefined conditional to identify VCL and FireMonkey?

As others says, there is not a conditional directive to determine if your application is VCL or FireMonkey. I think the most reliable way to determine if your app is FireMonkey or VCL is using a function instead of a conditional directive.

Something like

Uses
 Rtti;

function IsVCLApp:Boolean;
begin
 Result:= CompareText(TRttiContext.Create.GetType(TApplication.ClassInfo).QualifiedName,'Vcl.Forms.TApplication')=0;
end;

function IsFireMonkeyApp:Boolean;
begin
 Result:= CompareText(TRttiContext.Create.GetType(TApplication.ClassInfo).QualifiedName,'FMX.Forms.TApplication')=0;
end;

There does not seem to be a compiler define specifically for VCL/FireMonkey. You would need to create your own.

A list of predefined conditionals can be found in the documentation.


Although not documented you can have VCL and Firemonkey in the same application.

There is no compiler define.

If you're building something that needs to be both VCL and Firemonkey I would recommend separation of the units.

A possible way:

  • MyLibrary.X.pas - Common Code that both VCL, and Firemonkey would uses.
  • MyLibrary.Vcl.X.Pas - Vcl Specific Code
  • MyLibrary.Fmx.X.Pas - Fmx Specific Code

Mixing UI code from two different frameworks in the same unit is not a good idea. It will link in the other library when it's not needed.


There is no compiler directive because technically there is no such thing as a firemonkey application or a vcl application. Only applications which make use of these technologies. An application can use fxm or vcl or both or neither (eg. a console app). This is a bit like asking if it is an SQL application. You can of course programatically check the ancestry of individual forms to see which framework they inherit from. Again, inside a unit that has no associated form, this has no meaning.