TRVReporthelper and eDocEngine: Crash in complex document

General TRichView support forum. Please post your questions here
Post Reply
SculptureEK
Posts: 4
Joined: Wed Nov 21, 2012 3:24 pm

TRVReporthelper and eDocEngine: Crash in complex document

Post by SculptureEK » Sat Sep 14, 2019 2:50 pm

Hi!

I have TRichview version 17.6 and eDocEngine version 5.0.0.492.

I want to print complex documents which may have about 50 pages. The (very simplified) code is like this:

Code: Select all

      FEngine.BeginDoc;
      PageNumber := 1;
      Rvh.Init(FEngine.Canvas, Size.X);
      repeat
        if PageNumer > 1 then 
          FEngine.NewPage;
        Rvh.FormatNextPage(Size.Y - CurrentTop);
        Rvh.DrawPageAt(0, CurrentTop, PageNumber, FEngine.Canvas, False, Size.Y - CurrentTop);
        Inc(PageNumber);
      until not HasNextPage(PageNumber);
      FEngine.EndDoc;
FEngine is the eDocEngine Pdf class TgtPDFEngine, Rvh is TRVReportHelper.

This works for some documents but in other documents it crashes in the call to FormatNextPage for the last page. The call stack is:
TRVReportHelper.FormatNextPage()
TReportRVData.FormatNextPage()
TCustomMultiPagePtblRVData.PostFormat()
TCustomPrintableRVData.PostFormatPage()
TCustomRVFormattedData.AdjustItemsPrintingWidth()
TRVLabelItemInfo.GetFinalPrintingWidth()
TRVLabelItemInfo.DoUpdateMe()
TRVStyle.ApplyStyle()
TCustomRVFontInfo.Apply()

The crash is in the 3rd code line of Apply():
Font := Canvas.Font;

The reason is:
Canvas is retrieved in TCustomRVFormattedData.AdjustItemsPrintingWidth() using GetCanvas, which delivers TCustomMainPtblRVData.PrinterCanvas.
This is set up in Rvh.Init(). The problem is: FEngine.NewPage frees the old Canvas and allocates a new one.
So TCustomMainPtblRVData.PrinterCanvas is invalid after the first call to FEngine.NewPage.

I inserted this line in my code, before the call to Rvh.FormatNextPage():
TCustomMainPtblRVData(Rvh.rv.RVData).PrinterCanvas := FEngine.Canvas;

It seems to work, but it looks like a hack, not like a solution ;-)

Kind regards, Hans

Post Reply