Report Events
Previous Topic  Next Topic 

The main procedure in a script is executed when a report starts running. In the main procedure initial settings can be made and variables initialized. However this is not enough for total control over the process of report generation. To enable as much control as possible over report generation every object has several events to which handlers (i.e. procedures in the script) can be assigned. For example, connecting a handler to a text box can enable the script to perform calculations to diaply information in that text object.


As mentioned, the script's main procedure is called at the very start of running the report.   After the start of the report, other events are called as the report executes.  Firstly the OnStartReport event of the Report object is called. Then, before an output page is created, the OnBeforePrint page event is called. This event is called once for each design page in the report design (design pages should not be confused with the output pages of a report).   Then the events of the data bands are called in the following order: 


  1. The band's OnBeforePrint event is called
  2. The OnBeforePrint event of each object contained in the band is called
  3. Each object is filled with data 
  4. The OnAfterData event of each object is called
  5. Actions such as positioning objects on the band (if there are stretchable objects among them), calculating band height and stretching it (if it is stretchable) are performed
  6. The band's OnAfterCalcHeight event is called 
  7. A new output page is created if the band hasn't enough room in the page's white space
  8. The band and all of its objects are displayed on the output  page
  9. The OnAfterPrint event of each band object is called
  10. The OnAfterPrint event of the band itself is called


Bands continue to be printed as long as the source connected to the band has data. After that report printing stops, the report page's OnAfterPrint event is called and finally the Report object's OnStopReport event.


By using the events of different objects practically every step of the report creation process can be managed. The key to using events is a thorough understanding of the band output process.  Most of the actions can be performed using the band's OnBeforePrint event only.  Any modifications made to an object are displayed immediately.  However, if the band is stretchable, it is impossible to say in this event on which page the band will be printed since calculation of the band's height is performed in step 5.  It can be done, however, either in the OnAfterCalcHeight event in step 6 or in the OnAfterPrint event in step 9.  Note that in the last event the band will already have been output so modification to objects will not have any visible effect.

 

It is essential to clearly understand the "where and when" the bands are output and to understand the timing (calling order) of each of their events. Likewise, understanding the "where and when" for each of the objects contained in the bands.