delphiregion

Delphi Region compiler directive - backwards compatible unit files?


Given the desire to use the useful Region compiler directive in unit files, what's the best approach to allow these same units from being used in previous versions of Delphi? There doesn't seem to be a 'decent' approach. (Desired IDE version is Delphi 7)

I like having Regions above the method definitions to hide/display the method definition help and version history comments but I'd have to surround the Region directives with other compiler directives, which kinda kills the 'cleaness' of region compiler directives.

I suppose a preprocessor could be written to comment out all Region/EndRegion directives if using a version of Delphi which doesn't support regions..and add then back for later versions?

I'm not 100% switched to Delphi 2009 and need to support multiple IDE versions.


Solution

  • I'm assuming D7 doesn't want to copile {$REGION} or {$ENDREGION}? I only have D2007/9 installed and cannot check that.

    Try this:

    {$IFDEF undef}{$REGION 'bla'}{$ENDIF}
    //some code
    {$IFDEF undef}{$ENDREGION}{$ENDIF}
    

    D2009 editor creates a region as expected. D7 should ignore the $REGION/$ENDREGION if 'undef' is not defined.