Can I undefine a conditional in the command line?

If you don't come up with a command line option, you can always add additional conditionals in your units or include file like this:

{$DEFINE FOO}

// Allow us to undefine foo at the command line by defining UNDEFFOO
{$IFDEF UNDEFFOO}
  {$UNDEF FOO}
{$ENDIF}

{$IFDEF FOO}
  ...
{$ENDIF}

Then use -D to set UNDEFFOO.


You can use {$UNDEF NAME} to undefine a symbol, equivalent to #undef in C and C++. The facility to undefine a conditional is only applicable at a unit level and cannot be applied project wide. In other words you cannot unset conditionals at the command line. This is no different from the facilities offered by C or C++ toolsets.

A very common approach is to locate all your conditional definitions in a shared .inc file which is then included at the head of every source file that relies on those definitions. If you arrange things this way then you have all the flexibility that you need.

I know it will be of little consolation, but more recent Delphi versions have much stronger support for configuration management. Modern Delphi versions make use of the msbuild system. They allow the same configuration options to be used in the IDE and on the command line. There is flexibility to define, for example, debug and release build options and switch between them easily. I know I find it a great reassurance to know, for sure, that I am using the same build in the IDE as on the command line. I did not feel anywhere near so secure in legacy Delphi versions.