views:

210

answers:

3

Good Morning,

I have a unit which I want to use in two different programs, to tell the difference I wanted to Define a symbol and then check that in the unit.

In my DPR for the project I have;

program Project1;

{$Define MYDEF}  

uses
  Forms,
  ...

and in my Form1 file I have

procedure TForm1.FormCreate(Sender: TObject);
begin
 {$IfDef MYDEF}
   ShowMessage('boo');
 {$EndIf}
end;

however I don't get to see boo! Are definitions limited to a certain scope?

+3  A: 

http://stackoverflow.com/questions/1277309/delphi-2007-and-ifdef-directive-fails-to-see-our-conditional

Under your project add the define to 'Conditional Defines'

Wizzard
+2  A: 

The defines are local to the file. If you want them to be global, add them to the project options.

Gamecat
+1  A: 

Another solution is to have an includefile and include it in all units and the .dpr.

This solution is more delphi version independant.

If your defines are related to Delphi versioning, check out http://www.stack.nl/~marcov/porting.pdf for some tips how to setup a systematic structure in your defines.

Marco van de Voort