views:

704

answers:

2

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.

+7  A: 

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.

gabr
+1. Put on one line, and created with a code or live template this does neither kill cleanliness, nor is it more effort to write.
mghie
This works...and will mark as the answer, as mentioned in the original question. My real answer is to remove Regions for now and switch everything to 2009 as time permits.
Darian Miller
A: 

There are a few Delphi(7) editor-enhancement-components out there, that provide something like this. I think GExperts does.

If you're ok with an impact on your code, you might consider {$I } to split large files.

Stijn Sanders