1
votes

I am developing a new module for a large Application in Delphi 2010.

I have organized my sources in a project group of two projects, one to build the full application and one two launch my test suite (which shares some sourcecode with the main application).

During the initalization of a unit, i need to act differently depending on which of the two i was compiling.

unit MySharedUnit
var
  flag : TFlagValues;

implementation
[...]

initialization

if IsTestProject then
  flag := TestValue
else
  flag := ReleaseValue;
end. 

Currently, I use a project defined environment variable (defined in only one of the projects' options) to decide the active project.

My question is:

Is there another or more elegant way to do this, like a builtin #define'd value or so which would not require me to modify the project options by hand when the test application should be run in Release mode?

1

1 Answers

6
votes

Delphi knows conditional compilation like:

initialization
{$IFDEF FULLVERSION}
  flag := ReleaseValue;
{$ELSE}
  flag := TestValue
{$ENDIF}
end. 

You can set FULLVERSION (or any other name) in the project if you like.

With Delphi 2010 you can have a different set of options for Debug and Release versions.