Board index » delphi » Printing -- good examples of BeginDoc, EndDoc/Abort, exceptions?

Printing -- good examples of BeginDoc, EndDoc/Abort, exceptions?

Printing -- good examples of BeginDoc, EndDoc/Abort, exceptions?

Hi --

I would welcome some good examples of how to use these Printer methods,
and the correct use of exceptions in a BeginDoc/EndDoc print routine.
THANKS IN ADVANCE for any URLs or code snippets!

(You wouldn't think this would be hard to research, but the only example
shipped with D3 is in the Teechart sample code, and it contains errors
(e.g., using both EndDoc AND Abort in the event of a problem).  In
examining a number of Delphi books at the bookstore, I could find NO
complete examples there either!)

-- Kevin

 

Re:Printing -- good examples of BeginDoc, EndDoc/Abort, exceptions?


In article <kevink-0104991057480...@shs.pr.mcs.net>, Kevin C. Killion
wrote:
Quote
> Printing -- good examples of BeginDoc, EndDoc/Abort, exceptions?

> Hi --

> I would welcome some good examples of how to use these Printer methods,
> and the correct use of exceptions in a BeginDoc/EndDoc print routine.
> THANKS IN ADVANCE for any URLs or code snippets!

What are you trying to print and where are you having problems? At the
simplest level the following code should draw a big X on the paper:

 with Printer do
  begin
   BeginDoc;
   Canvas.MoveTo(0,0);
   Canvas.LineTo(PageWidth,PageHeight);
   Canvas.MoveTo(0,PageHeight);
   Canvas.Lineto(PageWidth,0);
   EndDoc;
  end;

You're just drawing on the printer canvas instead of on the form so most
of the GDI commands (e.g. TextOut) will work. Note that Printer.PageWidth
and PageHeight give you the size of the printable area in pixels. Don't
use absolute numbers of pixels to determine print positions; either work
to proportions of the page or get the printer resolution and turn the
required physical position into the corresponding number of pixels.

I will agree that most books just skim over printing..

Tony Bryer  SDA UK

Re:Printing -- good examples of BeginDoc, EndDoc/Abort, exceptions?


Quote
I wrote:
> I would welcome some good examples of how to use these Printer methods,
> and the correct use of exceptions in a BeginDoc/EndDoc print routine.
> THANKS IN ADVANCE for any URLs or code snippets!

to...@sda.co.uk replied:

Quote
> What are you trying to print and where are you having problems? At the
> simplest level the following code should draw a big X on the paper:

Just using BeginDoc and EndDoc is simple enough.  The trick is correctly
intercepting any error conditions with exception handling and proper use
of Abort.

As I said, the only sample code I've seen is that with Teechart, and I
know that it has errors (i.e., using both EndDoc AND Abort in the error
handling code).  And I have yet to find a book or online source with a
good example.

-- Kevin

Other Threads