[ACCEPTED]-Delphi #IF(DEBUG) equivalent?-compiler-directives
Use this:
{$IFDEF DEBUG}
...
{$ENDIF}
0
Apart from what lassevk said, you can also 26 use a few other methods of compiler-evaluation 25 (since Delphi 6, I believe) :
{$IF NOT DECLARED(SOME_SYMBOL)}
// Mind you : The NOT above is optional
{$ELSE}
{$IFEND}
To check if 24 the compiler has this feature, use :
{$IFDEF CONDITIONALEXPRESSIONS}
There 23 are several uses for this.
For example, you 22 could check the version of the RTL; From 21 the Delphi help :
You can use RTLVersion 20 in $IF expressions to test the runtime library 19 version level independently of the compiler 18 version level.
Example: {$IF RTLVersion 17 >= 16.2} ... {$IFEND}
Also, the compiler 16 version itself can be checked, again from 15 the code:
CompilerVersion is assigned a value 14 by the compiler when the system unit 13 is compiled. It indicates the revision level 12 of the compiler features / language 11 syntax, which may advance independently 10 of the RTLVersion. CompilerVersion 9 can be tested in $IF expressions and should 8 be used instead of testing for the VERxxx conditional 7 define. Always test for greater than 6 or less than a known revision level. It's 5 a bad idea to test for a specific revision 4 level.
Another thing I do regularly, is define 3 a symbol when it's not defined yet (nice 2 for forward-compatiblity), like this :
{$IF NOT DECLARED(UTF8String)}
type
UTF8String = type AnsiString;
{$IFEND}
Hope 1 this helps!
DebugHook is set if an application is running 3 under the IDE debugger. Not the same as 2 a compiler directive but still pretty useful. For 1 example:
ReportMemoryLeaksOnShutdown := DebugHook <> 0; // show memory leaks when debugging
These control directives are available:
{$IFDEF}
{$ELSE}
{$ENDIF}
{$IFNDEF} //if *not* defined
and 1 they can be used as shown here:
procedure TfrmMain.Button1Click(Sender: TObject);
begin
{$IFDEF MY_CONDITIONAL}
ShowMessage('my conditional IS defined!');
{$ELSE}
ShowMessage('my conditional is NOT defined!');
{$ENDIF}
{$IFNDEF MY_CONDITIONAL}
ShowMessage('My conditional is explicitly NOT defined');
{$ENDIF}
end;
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.