I was working on getting Log4D working in Delphi XE4, and was getting some compile errors because it couldn't find Contnrs in the uses clause, unless I moved it outside the ifdef it was defined in.
{$IFDEF DELPHI5_UP}
Contnrs,
{$ENDIF}
A little bit of investigating uncovered that the ifdef is defined in an included file Defines.inc which has a block for each "supported" version of delphi which stops a few versions back:
eg:
{$IFDEF VER170} { Delphi 2005 }
{$DEFINE DELPHI9}
{$DEFINE DELPHI4_UP}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
{$ENDIF}
{$IFDEF VER180} { Delphi 2006 }
{$DEFINE DELPHI10}
{$DEFINE DELPHI4_UP}
{$DEFINE DELPHI5_UP}
{$DEFINE DELPHI6_UP}
{$DEFINE DELPHI7_UP}
So while it would be easy enough to go ahead and copy and paste the ifdef for Delphi 2006 and create a Delphi XE4 block... this seems like an inelegant solution. It's definitely not future proof...every new version you have to go update this file now so some code that wasn't present in Delphi 4 doesn't make someone else's 15+ year old legacy code explode.
So I was wondering if there's a better way to do conditional compilation such that it really does just check whether you have "Delphi 5 or above" when compiling that line, rather than this format that requires updating every single new version of delphi that comes out.
${IF CompilerVersion >= 17}
{$DEFINE DELPHI_2005_UP}
{$ENDIF}
Much much less typing. And I prefer to type{$IFDEF DELPHI_2005_UP}This{$else}That{$endif}
through my actual code. – Presentday{$IF}
was introduced in Delphi 6. If you need to compile in Delphi 5 or earlier then you have to wrap{$IF}
statements inside an{$IFDEF CONDITIONALEXPRESSIONS}
block. – Buck