Board index » delphi » Delphi 2 (Developer) Richedit Control: Printing

Delphi 2 (Developer) Richedit Control: Printing

Hi

I am using NT4 W/S SP3 and cannot get the Richedit DEMO to print
[Delphi 2 Developer ver 2.01]. When the print button is clicked, the
proper Print Dialog for the HP DJ 720 appears, but the program then
stops with a DIV by zero Exception.

I am pretty sure others must have had this problem. Is there a bug in
RICHEDIT? - most of the code seems to lie in \Lib\Comctrls.DCU. I have
also tried running a test form with just Richedit, a button and the
PrintDialog. It hangs when the print button is clicked.

Michael Glover -  glo...@globalnet.co.xx
--
(Surrey, UK. http://www.users.globalnet.co.xx/~glover/ )
(Please change "xx" to "uk" to reply/access web site)

 

Re:Delphi 2 (Developer) Richedit Control: Printing


Quote
On Wed, 08 Dec 1999 22:00:38 GMT, M...@nospam.co.uk (MHG) wrote:
>I am using NT4 W/S SP3 and cannot get the Richedit DEMO to print
>[Delphi 2 Developer ver 2.01]. When the print button is clicked, the
>proper Print Dialog for the HP DJ 720 appears, but the program then
>stops with a DIV by zero Exception.

This is a known problem in Delphi 2, that has been corrected in later
releases. Search www.deja.com for more information (and a solution).

Hope this helps.

Good luck,
Jarle

Re:Delphi 2 (Developer) Richedit Control: Printing


This is a known bug in Delphi.... You need to get a hold of TI3204
You may want to try the Inprise site when its up and running (I'm getting
Forbidden access messages at this time)....

An old copy that I saved on my PC said:

***************************************************************

KEYWORDS: RichEdit, Print NT, Delphi 2 AREA: Utilities

TRichEdit Printing Under Windows NT 4.0

This document provides a Delphi Unit that will solve the
"divide by zero" error that occurs when printing from a
TRichEdit control under Windows NT 4.0.  To use this Unit
simply include it in the USES clause of the Unit that you
want to print from.  Instead of calling the RichEdit.Print()
method to print, call the PrintRichEdit() procedure and pass
it the TRichEdit control that you want to print as a parameter.

If you own the VCL source code you can make the changes
shown below to the TCustomRichEdit.Print method in the
COMCTRLS.PAS file.

unit PrtRichU;

interface

uses
  ComCtrls;

procedure PrintRichEdit(const Caption: string;
                        const RichEdt: TRichEdit);

implementation
uses
  Windows, RichEdit, Printers;

procedure PrintRichEdit(const Caption: string;
                        const RichEdt: TRichEdit);
var
  Range: TFormatRange;
  LastChar, MaxLen, LogX, LogY, OldMap: Integer;
begin
  FillChar(Range, SizeOf(TFormatRange), 0);
  with Printer, Range do
  begin
    BeginDoc;
    hdc := Handle;
    hdcTarget := hdc;
    LogX := GetDeviceCaps(Handle, LOGPIXELSX);
    LogY := GetDeviceCaps(Handle, LOGPIXELSY);
    if IsRectEmpty(RichEdt.PageRect) then
    begin
      rc.right := PageWidth * 1440 div LogX;
      rc.bottom := PageHeight * 1440 div LogY;
    end
    else begin
      rc.left := RichEdt.PageRect.Left * 1440 div LogX;
      rc.top := RichEdt.PageRect.Top * 1440 div LogY;
      rc.right := RichEdt.PageRect.Right * 1440 div LogX;
      rc.bottom := RichEdt.PageRect.Bottom * 1440 div LogY;
    end;
    rcPage := rc;
    Title := Caption;
    LastChar := 0;
    MaxLen := RichEdt.GetTextLen;
    chrg.cpMax := -1;
    OldMap := SetMapMode(hdc, MM_TEXT);
    SendMessage(RichEdt.Handle, EM_FORMATRANGE, 0, 0);
    try
      repeat
        chrg.cpMin := LastChar;
        LastChar := SendMessage(RichEdt.Handle, EM_FORMATRANGE, 1,
                                Longint(@Range));
        if (LastChar < MaxLen) and (LastChar <> -1) then NewPage;
      until (LastChar >= MaxLen) or (LastChar = -1);
      EndDoc;
    finally
      SendMessage(RichEdt.Handle, EM_FORMATRANGE, 0, 0);
      SetMapMode(hdc, OldMap);
    end;
  end;
end;

end.

***************************************************

HTH -- Denis

Quote
MHG (M...@nospam.co.uk) writes:
> Hi

> I am using NT4 W/S SP3 and cannot get the Richedit DEMO to print
> [Delphi 2 Developer ver 2.01]. When the print button is clicked, the
> proper Print Dialog for the HP DJ 720 appears, but the program then
> stops with a DIV by zero Exception.

> I am pretty sure others must have had this problem. Is there a bug in
> RICHEDIT? - most of the code seems to lie in \Lib\Comctrls.DCU. I have
> also tried running a test form with just Richedit, a button and the
> PrintDialog. It hangs when the print button is clicked.

> Michael Glover -  glo...@globalnet.co.xx
> --
> (Surrey, UK. http://www.users.globalnet.co.xx/~glover/ )
> (Please change "xx" to "uk" to reply/access web site)

--
Denis Boucher
Hull, Qubec
CANADA

Re:Delphi 2 (Developer) Richedit Control: Printing


Looks like Borland has reorganized its site once more... found this:

TI1532D TRichEdit Printing in Delphi 2 & Windows NT 4.0
    INPRISE Corporation delivers Borland software development tools to
make creation, deployment and
    management of distributed applications dramatically easier.
    http://www.borland.com/devsupport/delphi/ti/TI1532D.html - size 10.8K

Bye -- Denis

Quote
MHG (M...@nospam.co.uk) writes:
> Hi

> I am using NT4 W/S SP3 and cannot get the Richedit DEMO to print
> [Delphi 2 Developer ver 2.01]. When the print button is clicked, the
> proper Print Dialog for the HP DJ 720 appears, but the program then
> stops with a DIV by zero Exception.

> I am pretty sure others must have had this problem. Is there a bug in
> RICHEDIT? - most of the code seems to lie in \Lib\Comctrls.DCU. I have
> also tried running a test form with just Richedit, a button and the
> PrintDialog. It hangs when the print button is clicked.

> Michael Glover -  glo...@globalnet.co.xx
> --
> (Surrey, UK. http://www.users.globalnet.co.xx/~glover/ )
> (Please change "xx" to "uk" to reply/access web site)

--
Denis Boucher
Hull, Qubec
CANADA

Other Threads