DelphiFAQ Home Search:

Delphi compiler settings for debugging

 

comments6 comments. Current rating: 4 stars (4 votes). Leave comments and/ or rate it.

To be able to use the built-in debugger efficiently (and the same applies to external debuggers like TDW - Turbo Debugger for Windows), you need to ensure a few compiler settings are set the right way.

Important settings are:

  1. Optimization Off
    Enabling optimization would prevent you from examining the value of a variable after it has gone out of scope. A variable is gone out of scope if there is no further reading access to this variable in the flow of code even though you may be far from the end of a function's code block. At that point it is no longer available for inspection - there's no point holding on to what no one else is going to need, right? Usually this seems to happen just right after you want to look at this value.. but instead you get an error message "Variable 'XXX' inaccessible here due to optimization".
    So turn off optimizations for your debugging builds.
  2. Stack Frames On
    This supports the ability to view the call stack. If this option is not turned on, then certain types of calls will be optimized to the point where they cannot be viewed.
I've found these two to be critical in my work with Delphi 5. Other good options for debugging purpose are to enable all built-in checks like Range and Overflow Checking and of course to enable Assertions - if you use the assert() statement in your code. I use assert() heavily.

A note on assert():
Always make sure that the term in your assertion does not have side effects. Look at the example below. The first assertion is ok, the second assertion is a bad idea because the code will be very different when assertions are disabled.

A production build should never include enabled assertions!

var
  iResult : integer;

begin
  // good assertion
  // program flow is the same with assertions enabled or disabled

  iResult := function_call(x);
  assert(iResult > 0);

  // bad idea for an assertion:

  assert(function_call(x) > 0);

Comments:

2005-12-07, 06:21:45
anonymous from Netherlands  
rating
2007-04-07, 07:56:34
kuchmist@mail.ru from Ukraine  
rating
but why does the copiler kill my variable, if it's used in the prosedure. it works in thew first cycle and does not is the second one inside the CASE OF construction?
2008-02-23, 14:48:16
vortex.mr@hotmail.com from Sweden  
rating
Where can I find the compiler on my computer?

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.