简体   繁体   English

桌面和移动编译器的条件定义

[英]conditional defines for desktop and mobile compiler

I am working on a cross platform library that should compile in both desktop and mobile compilers supported by Delphi. 我正在开发一个跨平台库,该库应在Delphi支持的桌面和移动编译器中进行编译。 as we know strings in desktop is 1-based and mobile is 0-based. 我们知道桌面中的字符串基于1,移动设备基于0。 is there any defines in Delphi that I can use to separate code that will compile in desktop and mobile and is backwards compatible at least down to XE2. Delphi中有什么定义可用来分隔将在台式机和移动设备中编译的代码,并且至少向下兼容XE2。

something more like if defines desktop do this else if mobile do this. 如果定义桌面,则更像是这样做,而如果移动设备则更是如此。

sorry for bad formatting. 抱歉,格式化错误。 typing from Mobile. 从手机输入。

Delphi version XE7 up 1. Delphi XE7版本1。

The conditionals are documented here: http://docwiki.embarcadero.com/RADStudio/en/Conditional_compilation_(Delphi) 条件文档记录在这里: http : //docwiki.embarcadero.com/RADStudio/en/Conditional_compilation_(Delphi)

I think that the answer to the question that you asked is that you should switch on the NEXTGEN conditional. 我认为您所提出问题的答案是,您应该有条件地打开NEXTGEN

However, just because you are compiling for mobile (ie NEXTGEN ) does not mean that strings must zero based. 但是,仅因为您正在为移动设备进行编译(即NEXTGEN )并不意味着字符串必须从零开始。 Likewise there is no compulsion for desktop code to be one based. 同样,也没有强迫将桌面代码作为基础代码。 Zero based strings can be enabled/disabled with the $ZEROBASEDSTRINGS directive. 可以使用$ ZEROBASEDSTRINGS指令启用/禁用基于零的字符串。

You really ought to try to avoid conditional compilation. 您确实应该尝试避免条件编译。 Conditional compilation adds significant complexity, makes testing harder, and increases the risk off defects. 条件编译增加了相当大的复杂性,使测试更加困难,并且增加了缺陷的风险。 I strongly recommend you try to avoid conditional compilation where possible. 我强烈建议您尝试尽可能避免条件编译。

So for each unit you should decide whether you are zero or one based and include the appropriate directive at the top of that unit. 因此,对于每个单元,您应该确定自己是零还是一,并在该单元的顶部包含适当的指令。 If you plan to use the one based RTL functions like Pos and Copy , be one based. 如果您打算使用基于PosCopy基于RTL的功能,请使用基于1的RTL函数。 Otherwise use the string helper (introduced in XE3) and be zero based. 否则,使用字符串帮助器(在XE3中引入),并从零开始。 The decision isn't really related to whether or not your code targets desktop or mobile. 这个决定与您的代码是否针对台式机或移动设备无关。

Finally, you say you want to support mobile on XE2, but the compiler there is FreePascal which uses one based strings. 最后,您说要在XE2上支持移动设备,但是编译器中有FreePascal,它使用基于一个的字符串。 Supporting XE2 mobile is another layer of complexity. 支持XE2移动版是另一层复杂性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM