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-15, 10:47:42
anonymous from Ukraine  
Please, could you help me? My program that run in Delpi 4 for several minutes, now runs extremely slowly, the whole day long. It seems that it happened after updates of Windows XP. But I do not understand the reason. If I compile program on my computer and then run *.exe file on the computer with Windows 95, it runs very quickly, and vice versa the same program compiled under Delphi 3 on the computer with Windows 95, runs very quickly on my computer with XP. But when I compile the same program under Delphi 4 or 5 on computers with Windows XP and run on the same computers, which are much more powerful than the computer with Windows 95, the program hangs for extremely long time (it calculates but very and very slowly). I do not know how to cope with this situation. Elena.
2008-02-15, 11:00:13
esaft@biph.kiev.ua from Ukraine  
Please, could you help me? My program written under Delphi 4 that run for several minutes now runs extremely slowly (during the whole day). It is probable that it happened after updates of Windows XP, but I am not sure what could be the reason.
If I compile the program on my computer with Windows XP and then run on an old computer with Windows 95, it runs very quickly. The same program compiled under Delphi 3 on the computer with Windows 95 runs on my computer with Windows XP also very quickly. But if I compile it on my computer with Windows XP, under Delpi 4 or 5, it calculates extremely slowly. The same happens on the other more powerful computer with Windows XP. What may be the reason and is it possible to do anything to return to a normal work? Elena.
2008-02-23, 14:48:16
vortex.mr@hotmail.com from Sweden  
rating
Where can I find the compiler on my computer?
2008-10-20, 03:47:29
pmram@hotmail.com from India  
rating
Hi to all,
I am using delphi 7 and TMS Grid control. (TAdvStringGrid)
also i am having more than 1 million records on SQL Server. I want to
load that records to grid by loading on demand. That is if the user scroll
the mouse then only the next pages loaded fron server. is it possibe?
Please help me.

Thanks
P.Muthuraman

 

 

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.
 
It seems that you are
from Los Angeles, US .

Info/ Feedback on this

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.