Q:

How do I debug a stack overflow?

I was wondering if anyone has had a similar experience. I am trying to trace the source of a problem but am coming up with nil. I have a project in Delphi 5 which has Report Builder reports on it. I needed an upgraded version of reportbuilder so I tried running the project in Delphi 7. When my project runs and I click a button to view a report, it views fine. However, if I use a paramstr to run the report (showmainform is set false) and show report procedure runs, I get get a stack overflow error. 
The original code was :
 if lowercase(ParamStr(1)) = 'termsexceeded' then begin
    reportsdata.termsexceeded.close;
    reportsdata.termsexceeded.open;
    reports.ppTermsExceeded.print;
    reportsdata.termsexceeded.close;
    application.terminate;
  end; 

And it gave me the stack overflow error on the .print function.
The code that works in Delphi 7 is :
 if lowercase(ParamStr(1)) = 'termsexceeded' then begin
    reportsdata.termsexceeded.close;
    reportsdata.termsexceeded.open;
    reports.left := -10000;
    reports.show;
    reports.ppTermsExceeded.print;
    reportsdata.termsexceeded.close;
    application.terminate;
  end; 

Has anybody got a suggestion on how I could debug this to see if the problem lies with my Delphi 7 or with Reportbuilder ?
There are no events on the .show event of the reports form. 
Any advice on how to get to the bottom of this would be appreciated.
Regards

A:

When you get a stack overflow, use the debugger. It will interrupt your program when the OS throws the exception, and at that time, you can use the debugger's call stack window to see the path a function calls that lead there. You'll probably see a certain function or sequence of functions repeated many times.
When you've found the repeating pattern, check the code to see why it's repeating. Look for a condition is supposed to have changed, but doesn't.

