Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

PrinterSetup Question

edited January 2003 in General
What is the difference between the

1) ppReport1.PrinterSetup.MarginLeft := myMargin

and

2) ppReport1.Printer.PrinterSetup.MarginLeft := myMargin

The reason I ask is that if I make a margin change in 1) in the
OnPrintDialogClose the statement

Height :=
ppFromMMThousandths(ppReport1.PrinterSetup.PageDef.mmPrintableHeight,
utInches, pprtVertical, ppReport1.Printer);

does not reflect the new printable height, whereas if I make the
change as in 2), the change is reflected in PrintableHeight.

How do I know which one to use and when?

TIA.

Comments

  • edited January 2003
    I assume you mean MarginTop, not MarginLeft:)

    In this case you'll want to use the Printer object's PrinterSetup as you
    have found that this works. The PrinterDevice is created by the producer
    (the TppReport is a decendent of TppProducer). The printer setup is assigned
    to the PrinterDevice before the print dialog is created. See
    TppProducer.PrintToPrinter in ppProd.pas.

    if FPrinterDevice.Printer <> nil then
    FPrinterDevice.Printer.PrinterSetup := PrinterSetup;

    What happens is that the Printer is assigned to the dialog, and it is not
    copied, just assigned, as this is the declaration of this property:
    property Printer: TObject read FPrinter write FPrinter;

    Further along in the PrintToPrinter method, here is the call that assigns it
    in TppProducer.PrintToPrinter;
    lPrintDialog.Printer :=
    TppPrinterDevice(FPrinterDevice).Printer;

    Then after the print dialog is closed, and before the report is printed,
    this is called:

    {get printer device's printersetup - note: do not use assign here}
    PrinterSetup := FPrinterDevice.Printer.PrinterSetup;

    So, when you assign the printer setup, the real setup that is used is the
    PrinterDevice.Printer.PrinterSetup. Your change to the Report.PrinterSetup
    in the OnPrintDialogClose event gets overwritten with the
    PrinterDevice.Printer.PrinterSetup. Remember that the PrintDialog had a
    handle to the PrinterDevice.Printer which allowed it to make changes to the
    PrinterSetup on the PrinterDevice.

    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.