Compartir a través de


OnPreviewClose Method

Occurs when the user closes a report preview or opts to print from a report preview.

oReportListener.OnPreviewClose([lPrint])

Parameters

  • lPrint
    Specifies whether the user indicated a desire to print the pages in the current output page set after closing the report preview.

Return Value

None.

Remarks

Applies To: ReportListener Object.

The PreviewContainer API specifies that, when the user closes a report preview form, the PreviewContainer must call the ReportListener’s OnPreviewClose method. When the user chooses to print from Preview, Preview calls OnPreviewClose with an argument of True (.T.).

Note

The ReportListener invokes the PreviewContainer's SetReport method in OnPreviewClose with an argument of NULL (.NULL.). At this time, the ReportListener can choose to set its PreviewContainer reference to NULL (.NULL.) or retain it. However, according to the conventions of the PreviewContainer API, it is the responsibility of PreviewContainer to remove its back reference to the ReportListener at this time. For more information, see The Preview Container API and PreviewContainer Property.

If the user opted to print from preview, the print run starts after this method finishes. The print run uses cached pages prepared for preview at this point, so the available output exactly matches what the user saw in preview, including any RANGE or scope specifications included in the REPORT FORM command that invoked the preview.

If the ReportListener's CommandClauses.Prompt value is True (.T.) at this point, the printer setup dialog appears before the print run. The user may alter the specifications with which the report prints. This value may be True for one of the following reasons:

  • You used the PROMPT clause on the original REPORT FORM command.

  • The PreviewContainer or ReportListener adjust the CommandClauses.Prompt value dynamically.

The pages that print are not always the full range of available output pages; they may be some subset of this range. Fewer than the full number of output pages may print for one of the following reasons:

  • The user adjusts the page range in the PROMPT dialog.

  • The PreviewContainer or ReportListener adjusts the ReportListener CommandClauses members provided for the purpose of limiting printed output from the OnPreviewClose method. These members are PrintPageCurrent, PrintRangeFrom, and PrintRangeTo. For more information, see CommandClauses Property.

If you use NOPAGEEJECT to combine multiple reports within a single report run, the value of CommandClauses.Prompt is only significant at the moment the PreviewContainer invokes the print run. If you have not dynamically adjusted its value, the value of CommandClauses.Prompt has therefore been determined by whether the final REPORT FORM command in the report run included the PROMPT clause.

Important Note:

Because the printer setup dialog appears after the report has been rendered, in response to CommandClauses.Prompt, and because the report was rendered with information gathered from the printer set earlier, there is some potential for a mismatch between the previously-rendered report and the instructions set by the user in the dialog. For example, the printer chosen in the dialog might have a different printable page size than the original printer. The printed results in this scenario are determined by the way the chosen printer's driver chooses to handle this page size instruction.

Example

You can alter the various dynamic members of CommandClauses during the OnPreviewClose method, to print complex page ranges. In the following code sketch, a derived ReportListener provides a custom dialog to gather a complex page range from a user, and then invokes the native behavior multiple times to print the various page ranges requested by the user.

PROCEDURE OnPreviewClose(lPrint)
   LOCAL liRange
   IF lPrint
      NODEFAULT
      IF NOT EMPTY(THIS.CommandClauses.PrintPageCurrent
         *user chose "print current page" option from PreviewContainer.
         *Print only that page:
         THIS.CommandClauses.PrintRangeFrom = ;
           THIS.CommandClauses.PrintPageCurrent
         THIS.CommandClauses.PrintRangeTo = ;
           THIS.CommandClauses.PrintPageCurrent
         DODEFAULT(.T.)
      ELSE
         THIS.ShowCustomPageSetupDialog()
         THIS.CommandClauses.Prompt = .F.
         IF EMPTY(THIS.PageRangeArray[1])  
            * no printing is requested
            DODEFAULT(.F.)
         ELSE
            * user chose at least one range;
            * go through the array set up by 
            * the dialog and print the range(s)
            FOR liRange = 1 TO (ALEN(THIS.PageRangeArray,1))
               THIS.CommandClauses.PrintRangeFrom = ;
                 THIS.PageRangeArray[liRange,1]
               THIS.CommandClauses.PrintRangeTo = ;
                 THIS.PageRangeArray[liRange,2]
               DODEFAULT(.T.)
            ENDFOR
         ENDIF
      ENDIF
   ENDIF
ENDPROC

See Also

Reference

ReportListener Object

OutputPageCount Property

IncludePageInOutput Method

Other Resources

Methods (Visual FoxPro)

Language Reference (Visual FoxPro)