导航:
论坛 -> DELPHI技术
斑竹:liumazi,sephil
作者:
2021/10/26 9:44:44
标题:
在C++ Builder中编译时判断是VCL工程还是FMX工程
浏览:1096
加入我的收藏
楼主:
https://blog.csdn.net/dxkh/article/details/120953800 最近看到了一篇文章“Writing Cross Framework code in Delphi”,采用增加编译条件,获取工程文件中的某个变量,就不用手工修改编译条件了。具体配置和用法详见下面的代码: // 20211025 参考https://www.ideasawakened.com/post/writing-cross-framework-code-in-delphi // 在C++ Builder FMX工程中Project | Options | C++ Compiler | Directories and Conditionals | Conditional defines 添加 $(FrameworkType); // 在Delphi FMX工程中Project | Options | Delphi Compiler | Conditional defines 添加 $(FrameworkType); // VCL工程文件.cbproj中有 <FrameworkType>VCL</FrameworkType> 语句。 FMX工程文件.cbproj中有 <FrameworkType>FMX</FrameworkType>语句。 #ifdef FMX #define __IS_FMX__ #endif #ifdef VCL #define __IS_VCL__ #endif
----------------------------------------------
-
作者:
2021/10/26 10:15:53
1楼:
所有有效的条件,更不用说隐藏在 Embarcadero 中的许多条件了 https://docwiki.embarcadero.com/RADStudio/Sydney/en/Conditional_compilation_(Delphi) https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Conditional_compilation_(Delphi) etc...
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
2021/10/26 10:22:05
2楼:
Project Options => MyDefVar or on code.... {$DEFINE MyDefVar} on code: {$IF DEFINED(MyDefVar)} // IF NOT DEFINED() // x1 OR x2 // z1 AND z2 ... do that {$ELSE} /// ELSEIF other IFs ... this {$ENDIF} ---------- {$DEFINE Hello} {$UNDEF Hello} {$DEFINE HAlloW} procedure TViewFormMain.FormCreate(Sender: TObject); begin {$IF DEFINED(Hello) OR DEFINED(HAlloW)} ShowMessage('Hello'); {$ELSEIF NOT DEFINED(Hello)} {$IF DEFINED(World)} ShowMessage('World'); {$ELSE} ShowMessage('WoW'); {$ENDIF} {$ENDIF} // // {$IFDEF InternalVarCompiler >= 1.0} ShowMessage('Value >= 1.0'); {$ELSE} ShowMessage('Value < 1.0'); {$ENDIF} end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
2021/10/26 11:02:22
3楼:
有时为了使以前的代码可以用在FMX工程中,需要设置编译条件以便使用不同的语句,但是C++Builder没有提供编译条件。在网上查了一些文章,基本都是运行后才能判断是否为FMX或VCL程序。 为了实现这个功能,只能采取手工定义编译条件,当编译VCL工程时采用 #define _IS_VCL_ 当编译FMX工程时采用 #define _IS_FMX_ 这时需要注释掉 // #define _IS_VCL_ 这种方法暂时满足要求,就是需要手工修改。 —————————— 版权声明:本文为CSDN博主「我来看看CB」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/dxkh/article/details/120953800
----------------------------------------------
-
作者:
2021/10/26 11:03:48
4楼:
主要是为了以前的代码能用在FMX工程中。
----------------------------------------------
-