Conditional compilatation to detect VCL or FireMonkey in a Delphi Form

This shows how to detect if your application is using FireMonkey (FMX) or VCL when using conditional compilation in a Delphi form

UPDATE – a better solution has been provided by a Rudy Velthuis.  I recommend to use that instead of my original post.  Ive provided examples based on his feedback.  Thanks Rudy


   -- Rudy Velthuis' updated solution
{$IF not declared(FireMonkeyVersion)}
-- Making it even simpler, this is the same code
-- with the "not" removed so the logic is flipped

{$IF declared(FireMonkeyVersion)}

   -- a handy function that can be used in regular code
   -- rather than conditional compilation
function IsFMX : boolean;
 {$IF declared(FireMonkeyVersion)}
   result := TRUE;
   result := FALSE;


The following is my original post

{$IF FMX.Types.FireMonkeyVersion >= 0} // if FireMonkey
{$ELSE}                  // its not FMX, so it must be VCL

Can I Reverse the logic ?

No, reversing the logic does not work.  The reason for this is we are relying on the behaviour of Delphi conditional compile to return FALSE if the variable in the {$IF} does not exist.

To clarify … this  works correctly

{$IF FMX.Types.FireMonkeyVersion >= 0} // if FireMonkey
     ShowMessage ('FMX 1');
{$ELSE} // its not FMX, so it must be VCL
     ShowMessage ('VCL 1');

But this does NOT work

{$IF FMX.Types.FireMonkeyVersion < 0} // if VCL
     ShowMessage ('VCL 2');
{$ELSE}            // its not VCL, so it must be FMX
     ShowMessage ('FMX 2');


What if I mix and match VCL and FMX ?

Although not officially supported, it is possible for a Delphi application to use both FireMonkey and VCL units.

It is possible to embed a FireMonkey form in a VCL application and vice versa using unsupported techniques.  However, I haven’t tested those scenarios with my conditional compilation code.  Maybe it will work, maybe not.  Ill leave it to you to look into it if you are interested.  Please post a comment here if you find anything interested.

Supported Versions of Delphi

The code has been tested on XE2 to XE10.1

+1 this post

I am trying to get this blog listed on
If you like this post, please +1 for me here on Delphi Feeds

and here on BeginEnd

Thank You !

About The Author

The Usual Suspect
– Scott Hollows –

  • Oracle and Delphi software developer.
  • Australian Delphi User Group – Western Australia Chief Cat Herder
  • Australian Delphi User Group – President
blog email linkedinlogo

Author: Scott Hollows

Enterprise software developer based in Perth, Western Australia. Focused on Oracle, Delphi, Data Warehouse design and ETL, Data Architect, Business Intelligence, Oracle performance tuning. President of the Australian Delphi User Group (ADUG) LinkedIn

5 thoughts on “Conditional compilatation to detect VCL or FireMonkey in a Delphi Form”

  1. There is a similar trick mentioned in Embarcadero’s own documentation:

    “If the identifiers referenced in the conditional expression do not exist, the conditional expression will be evaluated as False:

    {$IF NoSuchVariable > 5}
    Writeln(‘This line doesn”t compile’);

    You can use the FireMonkeyVersion constant (defined in FMX.Types.pas and equal to 16.1 at the XE2 Update 2 release) in an IF directive. To identify and separate FireMonkey code that is for any version higher than 16.0, surround the code with the following conditional directive:

    {$IF Declared(FireMonkeyVersion) and (FireMonkeyVersion > 16.0)}


  2. Thanks – that works for me in VCL and FMX

    I think this is the best solution so far as it is more concise and does not have the issue of “reversing the logic does not work.” that I mentioned

    Im throwing in a Hello World so we have a copy / pasteable demo

    {$IF not declared(FireMonkeyVersion)}

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s