Jump to content
Ugochukwu Mmaduekwe

Compiler Defines for FireMonkey and VCL in inc files.

Recommended Posts

Hi all,

Is there a compiler define that I can use to distinguish between FireMonkey and VCL in my include file?

I want to use this define in my include file (.inc) that will be referenced in all my project units.

 

Lets say something like this.

 

I tried this but it doesn't seem to work in my inc file.

 

{$IF DECLARED(FireMonkeyVersion)}
{$DEFINE FMX}
{$ELSE}
{$DEFINE VCL}
{$IFEND}



Thanks.

Share this post


Link to post
1 minute ago, Markus Kinzler said:

FireMonkeyVersion

is a constant not a conditional define.

first of all, thanks for replying.
That's the exact problem I have, FireMonkeyVersion is a constant defined in FMX.Types meaning the uses clauses has to be present but unfortunately, I cannot have a uses clause in an include file.

Share this post


Link to post

Create or extend a file named UserTools.proj in %APPDATA%\Embarcadero\BDS\19.0 (for 10.2 Tokyo) with the following code:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
       <DCC_Define>FrameWork_$(FrameworkType);$(DCC_Define)</DCC_Define>
    </PropertyGroup>
</Project>

Now you can check for the project framework with {$IFDEF FrameWork_VCL} and  {$IFDEF FrameWork_FMX}.

  • Like 2
  • Thanks 4

Share this post


Link to post
16 minutes ago, Uwe Raabe said:

Create or extend a file named UserTools.proj in %APPDATA%\Embarcadero\BDS\19.0 (for 10.2 Tokyo) with the following code:


<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
       <DCC_Define>FrameWork_$(FrameworkType);$(DCC_Define)</DCC_Define>
    </PropertyGroup>
</Project>

Now you can check for the project framework with {$IFDEF FrameWork_VCL} and  {$IFDEF FrameWork_FMX}.

thanks a lot for this.

does anyone have the slightest idea why Embarcadero refuse to make a compiler define for this?

it would make our life far more easier.

 

Share this post


Link to post

The use of a specific library/framework is different than the compilation for different cpus or platforms. Then same compiler is used regardless if it's a vcl or a fmx project. You can even mix up both inside a program.

With onboard means Vcl is  only available in win32 and win64, but with CrossVCL it can also be used for macOS and Linux targets.

  • Thanks 1

Share this post


Link to post

Embarcadero could use the same approach as above in one of the target files in the Delphi bin folder. They already do similar things in there. I guess it is time to file a QP report for that.

Share this post


Link to post
8 hours ago, Uwe Raabe said:

Embarcadero could use the same approach as above in one of the target files in the Delphi bin folder. They already do similar things in there. I guess it is time to file a QP report for that.

Exactly, as a maintainer of a library which I want to extend support for Firemonkey (it already supports VCL and LCL), telling my end users to go through the usertools.proj method you stated above is to say the least very stressful.

Yes I know I could create a New Library with those features only for FMX but c'mon, who wants to go through that hurdle of maintaining two very similar libraries just because of the inability to differentiate between the two UI frameworks.

Share this post


Link to post

Cool trick @Uwe Raabe, i really like it even if i do not use FMX 🙂

 

VCL i know what it mean, but what stand LCL for? cant find reference in my Delphi Help.

Share this post


Link to post
Guest
12 minutes ago, KodeZwerg said:

Visual Component Library wich contain Lossless Compression Library :-]

Exactly

Share this post


Link to post

Well, you might as well add that FrameWork_$(FrameworkType) define directly to your project. That is mostly what @Markus Kinzler suggested before and limits the use to the current project, while the UserTools approach works for any project. In case of your library you would have to do that for each of its projects. Perhaps you can simplify it using an OptionSet.

Share this post


Link to post

Form the Delphi help, "IF directive":

 

Quote

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)}
  ...
{$IFEND}

 

This code works fine for me:

procedure TForm1.Button1Click(Sender: TObject);
begin
{$IF DECLARED(FireMonkeyVersion)}
  ShowMessage('Here is FireMonkey!');
{$ELSE}
  ShowMessage('Perhaps it''s VCL');
{$IFEND}
end;

 

Edited by Kryvich
  • Thanks 1

Share this post


Link to post

@Ugochukwu Mmaduekwe Try to put {$INCLUDE MY.INC} after uses clause with VCL or FMX files. The FireMonkeyVersion constant should be declared before you check it in your INC file.

Share this post


Link to post
9 minutes ago, Kryvich said:

@Ugochukwu Mmaduekwe OK Put FMX.Types to the top of the uses clause of your project file.

thanks for the help but I have already found another way round the issue.
either I use the method proposed by @Uwe Raabe above or I enable a define in my include file when I want to compile for FMX.
I think these options looks cleaner.

Share this post


Link to post

Yes, I was going to suggest to create frameworksetting.inc in your application source folder with a suitable define (FMX or VCL). And then {$include frameworksetting.inc} to every unit of your library. Then you don’t have to manually modify UserTools.proj on every developer's machine.

  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×