QuickReport.ExportToFilter throws "stack overflow" error when used in TWebModule

3k Views Asked by At

I have a web application using the TWebModule component. It runs as a module on Apache. The code below throws a "Stack Overflow" error on the ExportToFilter. The same exact code works fine from a Winforms Application and even a service for that matter. I have seen other discussions on this which indicate it has something to do with threading.

var
  mFileName: String;
  AExportFilter:;
begin
    mFileName := 'c:\temp\calendar.pdf';
    AExportFilter:=TQRPDFDocumentFilter.Create(mFileName);
    try

      WebSchdHistCalendarForm := TWebSchdHistCalendarForm.create(nil);
      WebSchdHistCalendarForm.quickrep1.ShowProgress := False;
      WebSchdHistCalendarForm.quickrep1.ExportToFilter(AExportFilter  );
    finally
     AExportFilter.Free;
     WebSchdHistCalendarForm.Free;
    end;
2

There are 2 best solutions below

1
On

If I'm not mistaken you get Stack overflow on infinite recursive method calls. This might not be the case here though.

0
On

Only 11 years late, but this might be useful to someone else, as I've just encountered this problem with one of my applications running on some Windows 10 machines.

(Actually in my case the Windows event log reported it as an access violation, but by running WinDbg on one of the problem machines I was able to see the initial cause was a stack overflow at the cvtInt() function.)

The fix is to mark the Buf parameter as const in a couple of functions in QRPDFFilt.pas:

function cvtInt(Buf: array of byte; P: Integer) : Integer;
begin
  Result:=(256*Buf[P])+(Buf[P+1]);
end;

should be:

function cvtInt(const Buf: array of byte; P: Integer) : Integer;
begin
  Result:=(256*Buf[P])+(Buf[P+1]);
end;

and likewise for cvtDWord():

function cvtDWord(const Buf: array of byte; P: Integer) : DWORD;

(Thanks to Marco Filho for this solution, found on devmedia.com.br)