RichEdit eating last line (Solution)
I'm using feereport 234 and after making some reports my clients discovered that many times the last line wasn't printed.
I found out to be a problem in the calculation of the Height of the richedit. Here is the modified code I'm using. This is in FR_rich file.
The first comment: No sense to keep going if we are under the min height
Second comment: Check that it is not a calculation problem when there is just one last line
DAvid.
I found out to be a problem in the calculation of the Height of the richedit. Here is the modified code I'm using. This is in FR_rich file.
function TfrRichView.DoCalcHeight: Integer;
var
Range: TFormatRange;
LastChar, MaxLen, LogX, LogY, NewDY, LowDy, HighDy: Integer;
StopRender, Fit: Boolean;
begin
FillChar(Range, SizeOf(TFormatRange), 0);
with Range do
begin
hdc := GetDC(0);
hdcTarget := hdc;
LogX := Screen.PixelsPerInch;
LogY := LogX;
LowDy := 0;
HighDY := 1000000;
MaxLen := SRichEdit.GetTextLen;
while HighDy - LowDy > 8 do //no tiene ning??n sentido seguir si ya pas?© el m?nimo
begin
NewDY := LowDy + (HighDy - LowDy) div 2;
rc := Rect(0, 0, Round(DX * 1440 / LogX), Round(NewDY * 1440.0 / LogY));
rcPage := rc;
LastChar := CharFrom;
chrg.cpMax := -1;
repeat
chrg.cpMin := LastChar;
LastChar := SRichEdit.Perform(EM_FORMATRANGE, 0, Integer(@Range));
Fit := (LastChar >= MaxLen) or (LastChar = -1) or (LastChar = 0);
StopRender := ((LastChar < MaxLen) and (LastChar <> -1)) or Fit;
until StopRender;
if Fit then
HighDy := NewDY else
LowDy := NewDY;
end;
ReleaseDC(0, hdc);
end;
SRichEdit.Perform(EM_FORMATRANGE, 0, 0);
if HighDy < MinHeight then begin
(* verificar que no sea un problema de c??lculo cuando queda una ??ltima l?nea *)
SRichEdit.Lines.Add('.');
HighDy := DoCalcHeight div 2;
SRichEdit.Lines.Delete(SRichEdit.Lines.Count-1);
end;
Result := HighDy;
end;
The first comment: No sense to keep going if we are under the min height
Second comment: Check that it is not a calculation problem when there is just one last line
DAvid.
Comments
The code in the original post IS the solution to the problem. I posted it in case someone else faced the issue.
In any case, the Freereport-utf project has the fix, and some other minor fixes.
DAvid.