Author: Brad Tharalson, CIS 72030,3045

After unpacking:   Installed Directory-
                     Print Preview sample project.
                        Samples Sub-Directory-
                          Delphi code used to create samples.
                        Clp2Dlfi Sub-Directory-
                          Project for converting xBase to Delphi code.
                        OrgFiles Sub-Directory-
                          Files as I use them, no changes

PrnInit.txt  Contains list of printers and Queues that are available.
             Loaded during StartLinePrinter().  If your printer is not on
             the list,  you will need to add it to the file, just add a
             new entry similar to the existing items.  Ignore the Queue
             stuff for now.

In the installed directory is the project file (PrnPrev.dpr) with samples
of using the wPreview unit.  Open the project, ignore the message, if any,
that says: Error Reading Symbol File.  Build and Run the program.

It starts with a Select Printer form, if your current printer is not shown
then please select it.  Make sure the "Preview Reports Before Printing"
checkbox is selected.

Under the "Preview Samples" menu choice, select any choice, these consist
of several prepared command list files that are then "Played Back", more
later. When on the Preview form, you can use the popup menu attached to the
right button to select the choices at the top of the Preview form if they
should scroll off the forms canvas.

For the "View Blue Print" selection, there are two bitmaps involved.  The full
size image is 2200x1700 (470k), the "Select" image is only 613x337.  The
"Select" image appears first, click anywhere on this image and wait
a few seconds, the appropriate area on the full image will come into view.
You can then use "Up","Down", etc., buttons to move around the image or if
you click on the full image the "Select" image reappears and you can select
a new area to view, in essence, hop back and forth.

Before you try the "Print Blue Print" test, make sure your printer resolution
is less than or equal to 300 DPI.  I've had problems with higher resolutions.

wPreview Unit Concept
---------------------

I tried to find a unit I could use to give my software the same "Print With
Preview" capability found in commercial packages.  Unfortunately I couldn't
find something to fit my needs.

Printing is very easy in Delphi using their supplied Printers unit.  For
years my end-users have been able to view plain text reports on the screen
before printing.  First, I wrote the routine to send each canvas page to
the screen or printer as they have chosen.  Then, they wanted to be
able to hop around among different pages and print as needed.

So I decided that I would capture all of parameters passed into the routines
I already use for printing. Search for AddCommand() lines in wPreview.pas.
If they wanted it to go directly to the printer the parameters are not saved,
and the commands are immediately processed.  Otherwise the commands are saved
in a TStringList object so the can be previewed when done formatting.

Each group of routines for a page are kept separate in their own TStringList
object, at any time a single page or all pages can be passed to the
PlayBackPage routine and it will clear the current drawing canvas and
process the commands in the TStringList in the same order they were created.

These TStringList objects can also be saved to a file for later playback,
see the SaveCommands and LoadCommands routines.  Most of the sample
choices are just command files that are being played back, these were
generated using our Job Costing system. The saving occured in the PlayBackPage
routine, search for SaveCommands() in PlayBackPage, you'll see where I
commented it out.

I have included the Delphi code used to generate the Command files that are
played back on the sample menu. Search for "StartDoc" in the Delphi files below:

Command File         Menu Choice
------------         -----------
DemoRout.txt      Preview Routing Card,  see Samples/RoutCard.pas
DemoJob.txt       Preview Job Cost,      see Samples/JBdet.pas
DemoInfo.txt      Preview Job Due/Ship,  see Samples/JCcommon.pas


Using The wPreview Unit
-----------------------

  Use "Select Printer" menu choice under "File" menu to set the print
  destination and whether to preview reports before printing.

  1.  Create "Lpr" object, use its methods to create format your print file.
  2.  "TPreview" form (Minimized) is created whether you want Report
      Preview or not.  This is nice because you will see icons showing
      all the reports you are currently formatting.
  3.  When you end your series of print commands with StopDoc(), one of two
      things will happen:
        a. Preview On: TPreview form is maximized, first page appears.
                       TPreview form stays open until you close it.

           Lpr --> Creates Commands List --> TPreview form created -->
             Lpr (destroyed) --> TPreview (standalone) uses its own Lpr
                                 object to view and/or print pages as needed.

        b. Preview Off: TPreview form is minimized until printing is done
                        and then closed.

           Lpr --> Commands Direct To Printer --> Lpr (destroyed)


Code Sample:   Print Customer Names List (simplified)
-----------

    procedure CustLIst;
    var lpp:Lpr;  { Lpr is in unit wPreview.pas }
        tdb:oDB:  { from DBserver.pas unit in Clp2Dlfi directory }
    begin
      lpp:=Lpr.create;
      tdb:=nil;
      dbUse(tdb,'cust');  { open Cust.dbf }
      with lpp do begin
        SetDestination;
        { Tell system, report is designed for 8 1/2 by 11 paper. If you had
          used "for14x11" instead, it would automatically condense print
          if a user selected a letter size paper printer, or full size print
          on a wide carriage printer, see PrnInit.txt file }
        StartDoc(for8x11,'Customer List');
        while not tdb.eof do begin
          { have to use "lpp.writeln" because WriteLn is built-in to Delphi,
            and it takes precedence if no object qualifier }
          lpp.writeln(tdb.s('name')+'  ('+tdb.s('cust_no')+')');
        end;
        StopDoc;
      end;
      dbClose(tdb);
      lpp.free;
    end;

SetDestination should only be called once just before starting a series
of StartDoc-StopDoc sequences.  You can use the wPreview.pas unit to
format several reports at the same time, some you may have wanted
to preview when done, others you may be sending to one or more different
printers.

Note: There is no BTPrint.pas file for the BTPrint.dcu file.  I was having
      some problems with the GetCanvas routine in Printers.pas in the VCL,
      I suspect it is somewhere in Win95.  So I moved the FCanvas declaration
      to the public section and set it to Nil in the TPrinterCanvas.Create
      routine.  I don't think I can give you this changed code because
      it's Borland's.  But I think I can give you the compiled unit which
      is all that is really necessary.  If you accidently remove the
      BTPrint.dcu unit, you can copy BTPrint.ucd to BTPrint.dcu. Or you
      can substitute the unit Printers unit for the BTPrint unit and correct
      "fcanvas" to canvas in a couple of places in wPreview.pas (the compiler
      would kick these out).

These are some packages I use in developing in case I didn't get all
references to these removed and some compile errors occur, just delete
any references:   All are available from Programmer's SuperShop and elsewhere.

wPreview.pas: Used in Capture() and EndCap() routines

  Apiary Netware Developer Suite For Delphi
  Apiary, Inc.

wPreview.pas: TrueBar Unit, TBarCode control;

  TrueBar II (Bar Code Library)
  American Barcode Systems, Inc.

DBserver.pas: Used extensively for database management .
              Not needed for printing.

  ROCKET DataBase Manager
  Successware, Inc.



Hope the samples and the wPreview.pas routines can save you some time.

Brad Tharalson
72030,3045