Conditional Defines

Conditional Defines

I often wish I’d could have a LARS defined globally for my IDE, so that my sordid testcode was ignored when other team members built my code.

18 thoughts on “Conditional Defines


  1. Project Options / Delphi Compiler / Build Configuration: Debug / Conditional Defines, enter “;LARS” after the “DEBUG” if exists and done! 🙂


    Or don’t You tought this? 🙂


  2. Nope, Kiss Nándor, that’s not a good solution, since the project files are committed to the VCS.  


    The only alternative that works, is a local include file that is not committed to VCS, but that is very impractical.


  3. In the Delphi IDE go to Tools – Options – Environment Options – Environment Variables. Create a new environment variable named DCC_Define with value LARS.


  4. Bill Meyer I’m not sure if I’ve got you right, but Lars wanted a global DEFINE that is valid for all projects and only for his personal machine. This cannot be achieved with DEFINES in the project file which are shared with his collegues.


  5. Bill Meyer The environment variable DCC_Define is added to the defines in the project file (search for DCC_Define in a dproj file).  So you can simply check for {$IFDEF LARS} in the code. This will evaluate to true only on Lars’ machine.


  6. It exists!? Thank you so much, Uwe Raabe! 👌


    This allows me to put in diagnostics code that doesn’t interfere with the debugging for the rest of the team, and that has very low risk of ending up in a release build, and yet can be committed to the VCS. 🙌


  7. Uwe Raabe Thanks. I must be missing something. I Open Tools, Options, Environment Variables, and I see the DCC_Define I put in. However, in project files, whether created before or after I created that variable, there is no evidence of it in the DPROJ, and using it in an $IFDEF fails.


  8. Bill Meyer You won’t see it in the DPROJ files – only a reference to $(DCC_Define). But it should work with $IFDEFs. At least it does for me and obviously also for Lars. You just have to reopen the current project to get the effect.


  9. Lars Fosdal Perhaps it is the version issue. I tried it in D2007. However, since there are other DCC_Define values declared (DEBUG, for one) I would have thought the version would not be an issue.

Leave a Reply