Using the dBL Print Control package
by Rick Miller ó August, 2004

THE dBLprint object is a control for setting and managing dBASE printer objects. This is accomplished by the user modifying a profile.

A profile has no affect on the windows printing system for other printing needs.  dBLprint uses a profile to assign properties to a dBASE printer object. The dBL Print Control package comes with two different ways to use dBLprint.

 

Working with the dBLprintButton control.

The easiest way to start using the dBLprint object is with the dBLprintButton (pushbutton) object.  After installation of the dBL Print Control package, start dBASE and change directories to the installation folder. Run the file dBLPrintDemo.wfm. Click the Add to Component Palette button. A dBLprintButton object will now be available in the Form designer.


Methods of dBLprintButton
 
  dBLprintButton Method
  choosePrinter()  opens a dialog for changing a profile.
  print()  prints a report using a profile.
  preview()
 
 displays a report in a form.
 

Properties of dBLprintButton
 
  dBLprintButton Property  Default 
  appname  "dBLPrint"  specifies the profile to work with.
  margins  false  used to determine whether to show the Margin adjustment area with choosePrinter()
  options  true  used to determine whether to show the Options button with choosePrinter()
  printer  ""  further specifies the profile to work with.
  reportClass  ""  report className to use with preview() or print() method.
  reportFile  ""  file name holding the reportClass property value.
  streams  false  used to determine whether to show the Margin adjustment area with choosePrinter()
  testClass  ""  report className used by the Test button with choosePrinter()
  testFile  ""  file name holding the testClass property value.
  viewerClass  ""  form className to use with the preview() method.
  viewerFile
 
 ""
 
 file name holding the viewerClass property value.
 

The profile that is used by an instance of dBLprintButton is determined by the two properties appname and printer. These properties would normally be assigned within the application. A good place to assign these properties is in an onOpen() event handler of either the dBLprintButton object or the form that contains it. They may also be assigned by any other means you can think of.

The choosePrinter() method opens a printer dialog. The dialog values are saved to a profile when the user selects the OK button in the dialog. The dialog makes use of seven properties: appname, printer, margins, streams, options, testClass, and testFile.

The print() method prints a report using a profile. It makes use of six properties: appname, printer, margins, streams, reportClass, and reportFile. What does the print() method do?

Back to the Top

Working directly with the dBLprint object

How is a dBLprint object created ?
 
 
oRef = new dBLprint( [<char> application name, [<char> printer name]])
// Example: oRef = new dBLprint("Payroll", "Reports")
   

Methods of the dBLprint object
 
  dBLprint Method
  enumPaperSize(<char> printer name)  returns a two-column array of printer paper sizes.
  enumPaperSource(<char> printer name)  returns a two-column array of printer paper trays.
  enumPorts(<array> printer names)  returns a one-column array of printer ports matching a printer array.
  enumPrinters()  returns a one-column array of printer names.
  get(<char> property name)  returns a property value.
  getPdriver(<char> printer name)  returns a driver name for use with _pdriver.
  getPort(<char> printer name)  returns a port name.
  getDefaultPrinter()  returns the windows default printer name.
  release()  releases object from memory.
  set(<char> property, <pVal> value)  sets a property value, returns true/false (success/fail).
  setDefaultLanguage(<char> language)  sets language for dialogs, returns true/false (success/fail).
  setDefaultPrinter(<char> printer name)  sets the windows default printer, returns true/false (success/fail).
  setPrinter(<pRef> printer object)  assigns properties to a printer object, returns true/false (success/fail).
  showPrinter([<int> hwnd])
 
 returns true/false (OK/Cancel).
 

Letís go ahead and create a profile . Then we will apply the profile to _app.printer.
 
 
set procedure to dBLprint.co additive
// Note: we are using dBLprint.co instead of dBLprint.cc 
// for compatibility with all 32 bit versions of dBASE.
oRef = new dBLprint("TestApp", "Checks") 
oRef.showPrinter()
// make a couple of selections and then click the OK button.

inspect(_app.printer)
// notice a few of the property values.

oRef.setPrinter(_app.printer)
// notice a few of the properties have changed. 
// You may need to toggle the tabs to refresh the inspector. 
// close the inspector.

inspect(oRef)
// the properties and methods of oRef (dBLprint) are displayed.

oRef.release()

   

Properties of dBLprint
 
  dBLprint Property  Default 
  colorNormal  "BtnFace"  colorNormal property of the showPrinter() dialog box.
  margins  false  do margin values get added to pageTemplate1 with setPrinter ?
  options  true  does the Options button appear with showPrinter ?
  reportClass  ""  report className used by showPrinter Test button.
  reportFile  ""  file name holding the reportClass property value.
 streams  false  do margin values get added to streamFrame1 with setPrinter ?
  text
 
 " Printer Selection"
 
 caption used in the showPrinter dialog.
 

Back to the Top

How does dBLprint work with a dBASE report object ?

The setPrinter() method is used to interact with 3 report objects:

A dBASE printer object has several properties affecting output.
 
  Property  Type  Values
  color  integer  0=Default, 1=Mono, 2=Color/Shades of gray.
  copies  integer  Number of prints to make.
  duplex  integer  0=Default, 1=None, 2=Duplex vertical, 3=Duplex horizontal.
  orientation  integer  0=Default, 1=Portrait, 2=Landscape. 
  paperSize  integer  Evaluates to a Width x Height paper size.
  paperSource  integer  Evaluates to a paper tray or bin.
  printerName  false  Name displayed in the windows printer applet. 
  printerSource  integer  0=Windows default, 1=dBASE default, 2=Specific Printer. 
  resolution  integer  0=Default, 1=Draft, 2=Low, 3=Medium, 4=High. 
  trueTypesFonts
 
 integer
 
 0=Default, 1=Bitmap, 2=Download, 3=Substitute, 4=Outline 
 

The dBLprint setPrinter() method assigns the reportís printer.printerSource a value of 2 (Specific printer) and printer.trueTypeFonts a value of 0 (Default). The remaining properties are assigned values based upon the profile in use.

When the margins property is true dBLprint will interact with pageTemplate1. Two numeric values (from the profile) are used. The first is added to the reportís pageTemplate1.marginLeft property. The other is added to the reportís pageTemplate1.marginTop property. These additions affect the position of all displayed information.

When the streams property is true dBLprint will interact with pageTemplate1.streamFrame1. Two numeric values (from the profile) are used. The first is added to the reportís pageTemplate1.streamFrame1.Left property. The other is added to the reportís pageTemplate1.streamFrame1.Top property. These additions affect the position of objects displayed on pageTemplate1.streamFrame1. The detailband, reportGroup, and other groups all reside on pageTemplate1.streamFrame1.

Back to the Top

Where is the beef (real world) ?

I have an application for Payroll. This application prints reports and checks. The ďReportsĒ print jobs are are printed in landscape mode. The ďChecksĒ print jobs are printed in portrait mode. dBLprint can be used to create two different profiles: one for reports and one for checks.

To establish a profile for report, link the following code to a Menu item for Printer Setup (Reports).
 
 
set procedure to dBLprint.co additive 
oRef = new dBLprint("Payroll", "Reports")
// Assign other properties as desired. 
// ie: oRef.margins := true
oRef.showPrinter()
close procedure dBLprint.co
   

To establish a profile for checks, link the following code to a Menu item for Printer Setup (Checks).
 
 
set procedure to dBLprint.co additive
oRef = new dBLprint("Payroll", "Checks")
// Assign other properties as desired. 
// ie: oRef.margins := true
oRef.showPrinter()
close procedure dBLprint.co
   

To use a profile when printing, you can use code such as shown below and call it from a Menu item.
 
 
// Notes: 
// The profile must be applied before issuing a report.render(). 
Local oRef, oRepo
set procedure to my.rep additive
set procedure to dBLprint.co additive
// Create report object.
oRepo = new myReport()
// Redirect report output to the Printer.
oRepo.output := 1
// Either create a dBLprint object with the "Reports" profile.
oRef  = new dBLprint("Payroll", "Reports")
// or create a dBLprint object with the "Checks" profile.
oRef  = new dBLprint("Payroll", "Checks")
// Assign other properties as desired. 
// ie: oRef.margins := true 
// Apply the profile to the report's printer.
oRepo.printer.parent = oRepo
oRef.setPrinter(oRepo.printer)
oRepo.printer.parent := null
// Run the report.
oRepo.render()
// Destroy objects.
oRef.release()
oRef := null
oRepo.release()
oRepo := null
close procedure dBLprint.co
close procedure my.rep
   

Thatís all there is !!
Best wishes to everyone when Printing dBASE Reports.

Back to the Top

To download the dBL Print Control Package,
click here

Additional information about dBLprint.


I would like to thank David L. Stone, my proof-reader, for the improvements he brought to this text.