delphiconditional-operatordelphi-xeconditional-compilation

Are conditional expressions broken within packages?


Consider the following snippet:

requires
  designide,
  rtl,
  vcl,
  {$IF RTLVersion < 19.0}            // E2026 Constant expression expected
  //{$IF CompilerVersion = 22.0}     // same as above
  vcljpg;
  {$ELSE}
  vclimg;
  {$IFEND}

It seems to be absolutely syntactically correct. However, the compiler chokes on it and reports Constant expression expected. What really happens here?

Technical: currently tested on XE (15.0.3953.35171) only.

Of course, workaround suggestions are welcome too.


Solution

  • I found the same issue in the past even with delphi 2007. As workaround, I use a inc file with the conditional defines and then use {$IFDEF} instead of {$IF}

    something like so

    {$I MyDefines.INC}
    
    
    requires
      designide,
      rtl,
      vcl,
     {$IFDEF DELPHI_XE_UP} //the DELPHI_XE_UP is defineed inside of MyDefines.INC
      uNewlib;
     {$ELSE}
      uOldLib;
     {$ENDIF}