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.

Comments

  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? :)

    ReplyDelete
  2. Which then of course leads to programs working on your machine and not compiling or not working on theirs.

    ReplyDelete
  3. Kiss Nándor that is only for a single project, Lars Fosdal want this for every project

    ReplyDelete
  4. Fabian S. Biehn 
    I know but that's a "good" beginning :)

    ReplyDelete
  5. 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.

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

    ReplyDelete
  7. Uwe Raabe What am I missing? I see that these can be accessed, but with somewhat less convenience than defines in the project.

    ReplyDelete
  8. 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.

    ReplyDelete
  9. Uwe Raabe I got that, but I do not see how you make use of it. Might just be having a dumb moment.

    ReplyDelete
  10. 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.

    ReplyDelete
  11. 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. 🙌

    ReplyDelete
  12. 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.

    ReplyDelete
  13. 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.

    ReplyDelete
  14. Works for XE5 and XE6.  I have not tried with with older versions.

    ReplyDelete
  15. 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.

    ReplyDelete

Post a Comment