Search code examples
delphiversiondelphi-11-alexandria

Is there a way to condition-define the code for Delphi 11.2 specifically instead of 11.x?


I know I can use {$IFDEF VER350} to detect Delphi 11.x.

What can I use to detect 11.2 specifically? For instance, if 11.1 or 11.3 versions do not have an issue, but 11.2 does.


Solution

  • VERxxx values are not updated during point releases.

    There are CompilerVersion, RTLVersion, and RTLVersionXXX constants that you can use with the {$IF} directive.

    CompilerVersion and RTLVersion are not guaranteed to always be updated on point releases. Sometimes RTLVersion is, depending on the extent of updates made to the RTL in a point release, and if Embarcadero remembers to increment the value.

    For your particular case, there are RTLVersion11x constants defined for each point release of 11.x:

    RTLVersion: Comp = 35;
    RTLVersion111: Boolean = True;
    RTLVersion112: Boolean = True;
    RTLVersion113: Boolean = True;
    

    So, you can first check if RTLVersion (or CompilerVersion) is 35.x for an 11.x release, and then check if RTLVersion112 exists and RTLVersion113 does not exist, eg:

    {$IF ((RTLVersion >= 35) AND (RTLVersion < 36))
          AND RTLVersion112
          AND (NOT RTLVersion113)}
    

    Starting with 12.0, there is a new GetRTLVersion() function, which is documented as including a minor version for update releases:

    Returns the RTL version number of the system unit when it is compiled. The RTLVersion constant can be used for the expression in the conditional compilation. GetRTLVersion includes two bytes:

    • Upper byte: It holds the RTL major version.
    • Lower byte: It holds the RTL minor version. Usually, the minor version is the number of the update release. For example, for RAD Studio 12 - Update 1, GetRTLVersion would return $2401.

    But, this would be a runtime check, not a compile-time check, and it doesn't help you for 11.x and earlier versions.