Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Share:
Notifications
Clear all

[Solved] Lazarus - Easy trick on how to use {$IFDEF DEBUG} for simple debugging

1 Posts
1 Users
0 Reactions
4,893 Views
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

With compiler directives you can compile/not compile parts of your code, for example:

{$DEFINE DEBUG}
...
  ShowMessage('Always there test message');
{$IFDEF DEBUG}
  ShowMessage('Debug test message');
{$ENDIF}
...

When DEBUG is defined, both messages will appear. If DEBUG is not defined only the first one will appear.

Now how can we "connect" this to running an application in Debug Mode vs Default or Release Mode?
This is (after some searching) relatively easy. Add the following line somewhere in the beginning of your code:

{$IFOPT D+} {$DEFINE DEBUG} {$ENDIF}

We nog get DEBUG defined if we run our application from the IDE in Debug Mode - all automatically 


   
ReplyQuote
Share: