Ugochukwu Mmaduekwe 42 Posted November 3, 2018 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
Markus Kinzler 174 Posted November 3, 2018 FireMonkeyVersion is a constant not a conditional define. Share this post Link to post
Ugochukwu Mmaduekwe 42 Posted November 3, 2018 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
Markus Kinzler 174 Posted November 3, 2018 And it is not appropriate for your problem. You have to set this define directly in your project. Share this post Link to post
Uwe Raabe 2063 Posted November 3, 2018 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}. 2 4 Share this post Link to post
Ugochukwu Mmaduekwe 42 Posted November 3, 2018 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
Markus Kinzler 174 Posted November 3, 2018 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. 1 Share this post Link to post
Uwe Raabe 2063 Posted November 3, 2018 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
Ugochukwu Mmaduekwe 42 Posted November 4, 2018 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
KodeZwerg 54 Posted November 4, 2018 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
KodeZwerg 54 Posted November 4, 2018 Visual Component Library wich contain Lossless Compression Library :-] Share this post Link to post
Guest Posted November 4, 2018 12 minutes ago, KodeZwerg said: Visual Component Library wich contain Lossless Compression Library :-] Exactly Share this post Link to post
Ugochukwu Mmaduekwe 42 Posted November 4, 2018 1 hour ago, KodeZwerg said: Visual Component Library wich contain Lossless Compression Library :-] LCL I meant was Lazarus Component Library. 🙂 Share this post Link to post
Uwe Raabe 2063 Posted November 4, 2018 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
Kryvich 165 Posted November 4, 2018 (edited) 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 November 4, 2018 by Kryvich 1 Share this post Link to post
Ugochukwu Mmaduekwe 42 Posted November 4, 2018 17 minutes ago, Kryvich said: Form the Delphi help, "IF directive": unfortunately, this method will not work in an include file, I did try it. Share this post Link to post
Kryvich 165 Posted November 4, 2018 @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
Ugochukwu Mmaduekwe 42 Posted November 4, 2018 @Kryvich, I tried it just now, Unfortunately, it didn't work. Share this post Link to post
Kryvich 165 Posted November 4, 2018 (edited) _ Edited November 4, 2018 by Kryvich Share this post Link to post
Ugochukwu Mmaduekwe 42 Posted November 4, 2018 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
Kryvich 165 Posted November 4, 2018 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. 1 Share this post Link to post