DelphiFAQ Home Search:
General :: Programming :: Delphi :: Delphi IDE
Information about the Delphi IDE, add-in experts and wizards.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

This is the FULL list of all articles in this category.

Featured Article

Delphi compiler settings for debugging

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);
 

Generated 0:01:39 on Oct 22, 2017