PDA

View Full Version : Ifdefs



dazappa
05-11-2009, 01:35 PM
Currently using FPC 2.2.4, and I've found these lovely things called IFDEFs.
Ex:

{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
Is there any way for me to define my own variables for these? I'd like to create an {$IFDEF DEBUG} so that the code won't be compiled and run in the final application, whereas just having a "if(debug) then" everywhere will be compiled and will be executed.

Legolas
05-11-2009, 04:02 PM
Yes, you can :)
Something like this should do the trick


{$define MyDebug}

{$ifdef MyDebug}
writeln('Debugging...');
{$endif}


Look also at http://community.freepascal.org:10000/docs-html/prog/progch2.html#x106-1060002

User137
05-11-2009, 05:50 PM
... whereas just having a "if(debug) then" everywhere will be compiled and will be executed.

That is unless compiler optimizes it out. If your debug variable is constant it just might do that but i'm not sure.

dazappa
05-11-2009, 09:40 PM
Yes, you can :)
Something like this should do the trick


{$define MyDebug}

{$ifdef MyDebug}
writeln('Debugging...');
{$endif}


Look also at http://community.freepascal.org:10000/docs-html/prog/progch2.html#x106-1060002

Thanks. The info on that link (+ ifdefs) seem oh-so-helpful. But, currently I really only needed/wanted the ifdefs but I'm sure I'll have a use for the others in the future.