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.
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.
Project Options / Delphi Compiler / Build Configuration: Debug / Conditional Defines, enter ";LARS" after the "DEBUG" if exists and done! :)
ReplyDeleteOr don't You tought this? :)
Which then of course leads to programs working on your machine and not compiling or not working on theirs.
ReplyDeleteKiss Nándor that is only for a single project, Lars Fosdal want this for every project
ReplyDeleteFabian S. Biehn
ReplyDeleteI know but that's a "good" beginning :)
Ok, that is true
ReplyDeleteNope, Kiss Nándor, that's not a good solution, since the project files are committed to the VCS.
ReplyDeleteThe only alternative that works, is a local include file that is not committed to VCS, but that is very impractical.
In the Delphi IDE go to Tools - Options - Environment Options - Environment Variables. Create a new environment variable named DCC_Define with value LARS.
ReplyDeleteUwe Raabe What am I missing? I see that these can be accessed, but with somewhat less convenience than defines in the project.
ReplyDeleteBill 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.
ReplyDeleteUwe Raabe I got that, but I do not see how you make use of it. Might just be having a dumb moment.
ReplyDeleteBill 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.
ReplyDeleteIt exists!? Thank you so much, Uwe Raabe! 👌
ReplyDeleteThis 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. 🙌
Lars Fosdal Glad to be helpful.
ReplyDeleteTested. Works perfectly :)
ReplyDeleteUwe 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.
ReplyDeleteBill 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.
ReplyDeleteWorks for XE5 and XE6. I have not tried with with older versions.
ReplyDeleteLars 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