Share via


LoadReport Event

Occurs previous to a report run, before output is initialized in the BeforeReport event. Provides access to report command clauses.

PROCEDURE Object.LoadReport

Parameters

None.

Remarks

Applies To: ReportListener Object.

LoadReport and UnloadReport are the two framing events of the report or label run; from the Report System's point of view, the report run has not yet started when it invokes LoadReport, and the report run has already ended when it invokes UnloadReport.

Consequently, these events allow you to perform certain setup and cleanup activities. For example, in LoadReport, you can change the contents of the report or label definition table (frx or lbx) because the Report Engine and ReportListener have not read the contents of the table at this point. The print job has not yet started, unless this REPORT FORM command continues the print job started in an earlier REPORT FORM command that used the NOPAGEEJECT keyword, so you can change the current printer setup.

Note

For information about the order of events in a report run, see Understanding Visual FoxPro Object-Assisted Reporting.

If you write code in the LoadReport event that returns a value of False (.F.), the report run will not proceed. The print spool will not be opened, preview will not be instantiated, further Listener events will not be called, and so on. This behavior is similar to the Load event for forms and formsets; for forms, if Load returns .F., the form does not instantiate.

The clauses with which you invoked REPORT FORM or LABEL FORM are available for your use in LoadReport; however, certain values are not yet calculated at this point. For more information, see CommandClauses Property.

Example

In the following example class definition, the report definition file (frx) specified in the REPORT FORM command is "swapped" for a temporary file during the LoadReport event. It is replaced in its original position during the UnloadReport event.

DEFINE CLASS rlswap AS ReportListener

   ListenerType = 1  && to see the results, use a preview
   realFRX = ""
   useFRX = ""
   tempFRX = FORCEPATH(SYS(2015),SYS(2023))

   PROCEDURE LoadReport
      THIS.realFRX = THIS.CommandClauses.FILE
      THIS.useFRX = GETFILE("frx")
      IF EMPTY(THIS.useFRX)
         RETURN .F.
      ENDIF
      SET DATASESSION TO THIS.FRXDataSession
      SET SAFETY OFF  && it's scoped to session anyway
      THIS.ClearFRX(THIS.tempFRX)
      RENAME  (FORCEEXT(THIS.realFRX,"frx")) TO ;
               FORCEEXT(THIS.tempFRX,"frx")
      RENAME  (FORCEEXT(THIS.realFRX,"frt")) TO ;
               FORCEEXT(THIS.tempFRX,"frt")
      COPY FILE  (FORCEEXT(THIS.useFRX,"frx")) TO ;
               FORCEEXT(THIS.realFRX,"frx")
      COPY FILE  (FORCEEXT(THIS.useFRX,"frt")) TO ;
               FORCEEXT(THIS.realFRX,"frt")
   ENDPROC

   PROTECTED PROCEDURE clearFRX(tFRX)
      IF FILE(FORCEEXT(tFRX,"frx"))
         ERASE FORCEEXT(tFRX,"frx")) NORECYCLE
      ENDIF
      IF FILE(FORCEEXT(tFRX,"frt"))
         ERASE FORCEEXT(tFRX,"frt")) NORECYCLE
      ENDIF
   ENDPROC

   PROCEDURE UnloadReport
      SET DATASESSION TO THIS.FRXDataSession
      USE IN FRX
      THIS.clearFRX(THIS.realFRX)
      RENAME  (FORCEEXT(THIS.tempFRX,"frx")) TO ;
               FORCEEXT(THIS.realFRX,"frx")
      RENAME  (FORCEEXT(THIS.tempFRX,"frt")) TO ;
               FORCEEXT(THIS.realFRX,"frt")
   ENDPROC

ENDDEFINE

See Also

Reference

ReportListener Object

UnloadReport Event

REPORT FORM Command

LABEL Command

Other Resources

Events (Visual FoxPro)

Language Reference (Visual FoxPro)