开发者

Conditional compilation depending on current active project

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
[...]开发者_StackOverflow中文版

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜