在XE5中所有条件编译如
{$IFDEF MSWINDOWS}
替换为
{$IF defined(MSWINDOWS)}
例如XE4中的System.Diagnostics.pas有
...
implementation
{$IFDEF MSWINDOWS}
uses Winapi.Windows;
{$ENDIF}
{$IFDEF MACOS}
uses Macapi.Mach;
{$ENDIF}
{ TStopwatch }
...
现在在 XE5 中它看起来像:
...
implementation
{$IF defined(MSWINDOWS)}
uses Winapi.Windows;
{$ELSEIF defined(MACOS)}
uses Macapi.Mach;
{$ELSEIF defined(POSIX)}
uses Posix.Time;
{$ENDIF}
{ TStopwatch }
...
是否有任何特殊原因我也应该迁移类似的调用?
最佳答案
根据 Delphi 文档:
http://docwiki.embarcadero.com/RADStudio/Rio/en/Conditional_compilation_%28Delphi%29
The conditional directives {$IFDEF}, {$IFNDEF}, {$IF}, {$ELSEIF}, {$ELSE}, {$ENDIF}, and {$IFEND} allow you to compile or suppress code based on the status of a conditional symbol.
{$IFDEF}
和 {$IFNDEF}
只允许您使用之前由 {$DEFINE ...}
设置的定义>.
然而 {$IF ..}
指令更加灵活,因为:
Delphi identifiers cannot be referenced in any conditional directives other than {$IF} and {$ELSEIF}.
const LibVersion = 6; //One constant to define the libversion.
{$IF LibVersion >= 10.0}
do stuff that covers LibVersion 10,11 and 12
{$ELSEIF Libversion > 5.0}
do other stuff that covers LibVersion 6,7,8,9
{$IFEND}
如果你尝试使用定义来做到这一点,你就必须这样做
{$DEFINE Lib1}
{$DEFINE Lib2}
{$DEFINE Lib3}
{$DEFINE Lib4}
{$DEFINE Lib5}
{$DEFINE Lib6} //all previous versions have to be defined.
{$IFDEF Lib10}
do stuff that covers LibVersion 10, 11 and 12
{$ELSE}
{$IFDEF Lib6}
do stuff that covers LibVersion 6,7,8,9
{$ENDIF}
{$ENDIF}
这只是处理定义的稍微高级的版本。
{$IF ..} 表示法更强大,它允许您查询常量表达式而不仅仅是定义。
{$IF ..}
指令是在 Delphi 6 中引入的。
我猜 Embarcadero 决定清理代码库。
关于delphi - 为什么在Delphi XE5中{$IFDEF MSWINDOWS}被替换为{$IF Defined(MSWINDOWS)}?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23597548/