OnPrintReport - cDRReport¶
Methods - Properties - Events
Method Type¶
Procedure (event)
Arguments¶
| Argument | Description |
|---|---|
hPrintDlg |
Address of a PRINTDLGEX structure. |
Description¶
This event is sent by the object at the start of the PrintReport method.
When the property pbCanceled is set to true during this event, the printing will not be done.
The address of the PRINTDLGEX structure is passed and may be changed. Note that this value might be zero, which tells PrintReport to take care of the printer selection. For more information about the PRINTDLGEX structure, see:
http://msdn.microsoft.com/library/ms646844.aspx
DataFlex Framework usage¶
- Web
- Windows
- FlexTron
Sample¶
Object oReport is a cDRReport
Set psReportName to 'MyReport.dr'
Procedure OnPrintReport Handle ByRef hPrintDlg
Forward Send OnPrintReport (&hPrintDlg)
// Would cancel the printing
Set pbCanceled to (Not (IsAdministrator ()))
End_Procedure
End_Object
The event can be used to control the page range that needs to be printed. For that, create an input control where the user can enter the range value(s). Users will expect they can enter a value like "1-4" or a value "1-2,4". Then parse the entered value into PRINTPAGERANGE values and pass a variable of this struct via the pPageRanges properties of the print dialog object. Code could be:
Procedure OnPrintReport Handle ByRef hPrintDlg
Handle hoPrintDialog
PRINTPAGERANGE[] PageRanges
String sPageRangeValue
String[] sPageRanges
Integer iElements iElement iDashPos
Forward Send OnPrintReport (&hPrintDlg)
Get phoPrintDialog to hoPrintDialog
Get Value of oPageRangeForm to sPageRangeValue
Move (Trim (sPageRangeValue)) to sPageRangeValue
If (sPageRangeValue <> '') Begin
Move (StrSplitToArray (sPageRangeValue, ',')) to sPageRanges
Move (SizeOfArray (sPageRanges)) to iElements
If (iElements > 0) Begin
Decrement iElements
For iElement from 0 to iElements
Move (Pos ('-',sPageRanges[iElement])) to iDashPos
If (iDashPos > 0) Begin
Move (Left (sPageRanges[iElement], iDashPos - 1)) to PageRanges[iElement].nFromPage
Move (Right (sPageRanges[iElement], Length (sPageRanges[iElement]) - iDashPos)) to PageRanges[iElement].nToPage
End
Else Begin
Move sPageRanges[iElement] to PageRanges[iElement].nFromPage
Move sPageRanges[iElement] to PageRanges[iElement].nToPage
End
Loop
End
End
Else Begin
Move 1 to PageRanges[0].nFromPage
Get ReportPageCount to PageRanges[0].nToPage
End
Set pPageRanges of hoPrintDialog to PageRanges
Set piFlags of hoPrintDialog to (PD_USEDEVMODECOPIES ior PD_DISABLEPRINTTOFILE ior PD_PAGENUMS ior PD_SELECTION)
End_Procedure
The above code starts with getting a handle of the cPrintDialog child object that gets created with each cDRReport object stored in phoPrintDialog. Then the entered value is parsed and split into (if present) individual PRINTPAGERANGE elements. Finally, the piFlags property is changed so that printing is instructed to use the passed page numbers.