The Delphi Bug List

Entry No.
80
VCL - Win32 - ComCtrls - TRichEdit
Documentation bug: the PageRect property contains co-ordinates in pixels, not twips
1.02 2.01 3.0 3.01 3.02 4.0 4.01 4.02 4.03 5.0 5.01 6.0 6.01 6.02 Kylix 1.0
N/AGotchaExistsExistsExistsExistsExistsExistsExistsExistsExistsFixedFixedFixedN/A
Description
Reported by Brad Stowers; checked by Borland (D4.02 readme)
The D3 documention lists a property named PageRect for the TRichEdit control which claims to be the printable area in twips (1/20th of a point, or 1/1440 of an inch). The source code, on the other hand, uses a formula that converts from pixels, not twips: (from SOURCE\VCL\COMCTRLS.PAS, TRichEdit.Print method)
  else begin
    rc.left := PageRect.Left * 1440 div LogX;
    rc.top := PageRect.Top * 1440 div LogY;
    rc.right := PageRect.Right * 1440 div LogX;
    rc.bottom := PageRect.Bottom * 1440 div LogY;
  end;
What this does is convert from pixels *TO* twips.

The bug is in Delphi 3.0 (3.01 could not be checked yet) and Delphi 2.01, although in 2.01, PageRect was undocumented, so it's not really a bug there.

To reproduce the bug:
Try to manually set PageRect to a know value of twips, say for 2" margins:

  MyRichEdit.PageRect := Rect(2*1440, 2*1440, round(6.5*1440), 9*1440);
  MyRichEdit.Print('test');
It won't work. But if you use pixels, it will:
var
  LogX, LogY: integer;
begin
  LogX := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
  LogY := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
  MyRichEdit.PageRect := Rect(2*LogX, 2*LogY, round(6.5*LogX), 9*LogY);
  MyRichEdit.Print('test');
end;
Also, it might be good to note that you have to manually adjust for the non-printable area, too. If you use the above, and your printer has a non-printable area of 1/2" on the left, you will really get a left margin of 2 1/2" inches. I left that out in the example to make the code a little more clear.
Latest update of this entry: 2001-07-04

Post a comment on this bug


Index page
Delphi Bug List home page
The Delphi Bug Lists are presently maintained by Jordan Russell, who has taken over this task from Reinier Sterkenburg since August 2000.
All feedback is appreciated. See also the feedback section of the Delphi Bug List home page.