#1 2016-02-06 01:00:44

alexf
Member
Registered: 2016-02-06
Posts: 1

Bug in mORMotReport.pas - TGDIPages.AppendRichEdit

Hello,

I wasn't sure how to report a bug, so I'm posting it here... I hope this is appropriate and someone who can make the change in the source finds this.

The issue comes when you want to use the AppendRichEdit method of TGDIPages in mORMotReport.pas.

If you populate the RichEdit with enough lines that additional pages must be added (say a couple hundred lines) then the header is not visible on the additionally inserted pages.

Actually, I think the header is being drawn, but is being overwritten by the Rich Text...
The fix I have found is re-applying the "Top" after the Header is written...

I have only started (Yesterday) looking at this library, so I don't know if this is actually an appropriate way to address the issue, so hopefully someone who knows can weigh in here.

Thanks!


Here is the method below with the fix I have found to work highlighted:

procedure TGDIPages.AppendRichEdit(RichEditHandle: HWnd;
  EndOfPagePositions: PIntegerDynArray);
var Range: TFormatRange;
    LogX, LogY, LastChar, MaxLen, OldMap: integer;
    TextLenEx: TGetTextLengthEx; // RichEdit 2.0 Window Class
begin
  if (Self<>nil) and (fCanvas<>nil) then
  with Range do begin
    LogX := GetDeviceCaps(fCanvas.Handle, LOGPIXELSX);
    LogY := GetDeviceCaps(fCanvas.Handle, LOGPIXELSY);
    rcPage.Left := (fPageMarginsPx.Left*1440) div LogX;
    rcPage.Right := ((fPhysicalSizePx.x-fPageMarginsPx.Right)*1440) div LogX;
    rcPage.Top := ((fPageMarginsPx.Top+fHeaderHeight)*1440) div LogY;
    rcPage.Bottom := ((fPhysicalSizePx.y-fPageMarginsPx.Bottom-fFooterHeight)*1440) div LogY;
    CheckHeaderDone;
    rc := rcPage;
    rc.Top := (fCurrentYPos*1440) div LogY;
    LastChar := 0;
    with TextLenEx do begin
      flags := GTL_DEFAULT;
      codepage := CP_ACP;
    end;
    MaxLen := SendMessage(RichEditHandle, EM_GETTEXTLENGTHEX, Integer(@TextLenEx), 0);
    chrg.cpMax := -1;
    OldMap := SetMapMode(hdc, MM_TEXT);
    try
      SendMessage(RichEditHandle, EM_FORMATRANGE, 0, 0);
      repeat
        chrg.cpMin := LastChar;
        hdc := fCanvas.Handle;
        hdcTarget := hdc;
        LastChar := SendMessage(RichEditHandle, EM_FORMATRANGE, 1, Integer(@Range));
        if EndOfPagePositions<>nil then
          AddInteger(EndOfPagePositions^,LastChar);
        if cardinal(LastChar)>=cardinal(MaxLen) then
          break;
        NewPageInternal;
        DoHeader;
        rc := rcPage;
//-------------------------------------------------------------------------------------------------------------------------------------------------------
        rc.Top := (fCurrentYPos*1440) div LogY;   // This new line is the only change. It seems to expose the Header on additional pages.
//-------------------------------------------------------------------------------------------------------------------------------------------------------
      until false;
      fCurrentYPos := (rc.Bottom*LogY) div 1440;
    finally
      SendMessage(RichEditHandle, EM_FORMATRANGE, 0, 0);
      SetMapMode(hdc, OldMap);
    end;
  end;
end;

Offline

Board footer

Powered by FluxBB