Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 237
Darian Miller Avatar asked Dec 17 '22 08:12

Darian Miller


1 Answers

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.

like image 181
gabr Avatar answered Dec 24 '22 01:12

gabr