Controlling the Printer

TECH TIP: Controlling the Printer

The PrinterSetup Class

You can control which printer is selected for a report and its associated properties at either design-time or run-time. You can also do things like print to two different printers at once or have a report that consists of multiple section type subreports with each section going to a different printer.

The Report.PrinterSetup object that contains properties for controlling the printer. You can set these via the object inspector at design-time or from the File | PageSetup dialog in the Report Designer.

At run-time you can control the Report.PrinterSetup properties via code. The PrinterSetup object contains a number of public properties that can be used to determine the valid values that are available. PrinterSetup.PrinterNames can be used to determine what printers are installed on the computer. PrinterSetup.PaperNames and BinNames can be used to determine the available paper and bin names for the
currently selected printer. (for more info, see the RBuilder.hlp file topic for TppPrinterSetup.)


Run the demos\reports\demo.dpr application and check out the printer settings section. There is a demo that displays a tabbed dialog showing all printer settings – this dialog is manipulating all of the PrinterSetup properties.

The Printer class

ReportBuilder has a TppPrinter class. A global ppPrinter object is used for some tasks, but when a print job is created a TppPrinter is created for the specific print job. In fact, one of the demos shows a report going
to 2 printers at once.

The TppPrinter.PrinterSetup property is an object of type TppPrinterSetup as is the Report.PrinterSetup property. You specifiy settings for the Report.PrinterSetup object and then they are transferred to
TppPrinter.PrinterSetup at the appropriate time.

If you want to control things more you can instantiate your own TppPrinter object and show the print dialog by calling TppPrinter.ShowSetupDialog: Boolean. The TppPrinter will automatically assign the results to the Printer.PrinterSetup object. You could then transfer the results to the report:

Or you can show some other dialog and transfer the results to the Report.PrinterSetup in some other manner. Run the RBuilder\Demos\Report\Demo.dpr project and check out the printer section.

Normally when you want to print to the printer you do something like:

But you can also create a TppPrinter object and use the Report.PrintToDevices to print a report to one or more devices. Again, see the printer section of the demo.dpr project for an example.