OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Creating a Printer Object

Declaring TPrinter

The easiest way to create a printer object is to declare a TPrinter* in your window object that other objects in the program can use for their printing needs.

class MyWindow : public TFrameWindow
{
.
.
.
protected:
TPrinter* Printer;
.
.
.
};

Making the printer available

To make the printer available, make Printer point to an instance of TPrinter. This can be done in the constructor:

MyWindow::MyWindow(TWindow* parent, char *title)
{
.
.
.
Printer = new TPrinter;
}

You should also eliminate the printer object in the destructor:

MyWindow::~MyWindow()
{
.
.
.
delete Printer;
}

Example

Here is how it is done in the PRINTING.CPP example from directory CLASSES\PRINTING:

class TRulerWin : public TFrameWindow
{
.
.
.
protected:
TPrinter* Printer;
};
TRulerWin::TRulerWin(TWindow* parent, const char* title, TModule* module)
: TFrameWindow(parent, title, 0, false, module),
TWindow(parent, title, module)
{
.
.
.
Printer = new TPrinter;
}

For most applications, this is sufficient. The application's main window initializes a printer object that uses the default printer specified in WIN.INI. In some cases, however, you might have applications that use different printers from different windows simultaneously. In that case, construct a printer object in the constructors of each of the appropriate windows, then change the printer device for one or more of the printers. If the program uses different printers but not at the same time, it is probably best to use the same printer object and select different printers as needed.

Note
Although you might be tempted to override the TPrinter constructor to use a printer other than the system default, the recommended procedure is to always use the default constructor, then change the device associated with the object.

See Also