On Conditional Compilation

Following up the discussion about conditional compilation that evolved from David Millington’s post on Google+  – as I mentioned there in my comments (and this answer on stackoverflow) I suggest using conditional compilation based on {$IF-constructs checking the built in constants CompilerVersion and RTLVersion. C’mon, this is available since Delphi 6 (nearly 15 years now)! It makes life so much easier.

If we only could have named constants for each Delphi version so one doesn’t have to remember which version has which number. A common complaint regarding this feature.

Here is my answer to it:

Update: Fixed wrong CompilerVersion values. Thanks to Stefan Glienke for point this out.

Want to check for string helpers (introduced in XE3)?

I would love to see these constants baked into the next System.pas.

Update: As Oliver correctly mentioned in his comment on my Google+ post, this won’t help anyway because it will only affect the newest version. Checking for “less than the current version” simply won’t work in older versions as those cannot gain knowledge of that now current version after they are released. So the above example simply would not work in XE2 (assuming those constants would have been available then) just because something like RTLVersionXE3 was probably not declared at that time. (The problem are not the numbers but the names.) As he also pointed out, a better solution would be to have those declarations publicly available and officially managed by Embarcadero.

Side note: I was a bit surprised to find checking for CompilerVersion inside the delivered Delphi sources. Not a bad move, IMHO.

 

About Uwe Raabe

Addicted to Pascal/Delphi since the late 70's
This entry was posted in Delphi, Programming. Bookmark the permalink.