Does Delphi's conditional compilation allow the defined symbols to contain values?

In Delphi, you can define symbols, just like in C/C++.




#define MY_SYMBOL

This allows you to check whether the symbol is defined by using {$IFDEF MY_SYMBOL} in Delphi, or #ifdef MY_SYMBOL in C/C++.

This is a boolean value - either the symbol is defined during pre-processing or not. However, C/C++ also allows you to assign values to preprocessor symbols. E.g.:

#ifdef DEBUG
#define DB_HOST ""
#define DB_HOST "123.456.789.123"

Database *pDatabase = new Database(DB_HOST);

Is assigning a value to a preprocessor symbol possible in Delphi, or does Delphi only allow you to determine whether or not a symbol has been defined at all?

EDIT: As Delphi doesn't support symbol values in the preprocessor, I'm assuming it doesn't support preprocessor macros. Am I right in this assumption?

For example, in C you can define a preprocessor macro that gets copied and pasted with the appropriate parameters before compilation. This is useful when you want "inline function" capability for fast operations (e.g., binary logic, testing in an integer values, bit-shifting, etc) without the overhead of stack frames, parameter passing and the like.

#define OK_FLAG 0x00000001
#define OK(f) (f & OK_FLAG)

#define WEAK_XOR_CIPHER(v) (v ^ 0xff)


You can simply use a constant, and define the value:

  DB_Host = '';
  DB_Host = '';

You can also do the reverse (test for something not being defined):

  DB_Host = '';
  DB_Host = '';

This ensures that DB_Host is always available, and has the appropriate value when not debugging.

Recent versions of Delphi allow you to test the value of constants. For instance, the System unit has the constant RTLVersion defined, and you can test for a value using it:

{$IF RTLVersion <= 26}
  // Less than XE5
  // XE5

Delphi doesn't support macros of any sort, however. The typical solution to not having macros is to use an inline function. See, for instance the Windows unit's implementation of the WinAPI RGB macro:

function RGB(r, g, b: Byte): COLORREF; inline;

function RGB(r, g, b: Byte): COLORREF;
  Result := (r or (g shl 8) or (b shl 16));

Need Your Help

Objective-Zip: Store content when unzip file (iOS)

ios objective-c unzip objectivezip

I just want to create a file with the data of unzipped file in iOS.

Detecting jQuery Object

javascript jquery object

I'm writing a plugin for jQuery and I want to make it so the user can pass data to the plugin in any form. I have the JSON or array problem worked out, but I'm having trouble trying to determine if...