Report events
In order to control the report with maximum flexibility, every report object has got several events. For example, in a handler, connected to the "Data" band, you can filter records, that is, hide or show the band depending on certain conditions.
Let us consider the events which are fired during the report generation process. As an example, we will take a simple report, containing one page, one "Data" band and two "Text" objects on the band:
In the beginning of the report, the "Report" object fires the StartReport
event. Before formation of the report page, the StartPage
event is fired. This event is fired once for every template page (do not confuse with prepared report page!). In our case, regardless of how many pages were in the prepared report - event is fired once, since the template report has got one page. Then the CreatePage
event is called, which occurs just at the moment when the page is created in the prepared report.
Further, printing of the "Data" band row starts. This happens in the following way:
- the
BeforePrint
band event is fired; - the
BeforePrint
event of all objects lying on the band is fired; - all objects are filled with data;
- the
AfterData
event of all objects lying on the band is fired; - the
BeforeLayout
band event is fired; - objects are placed on the band, the height of the band is calculated and band is stretched (if it can);
- the
AfterLayout
band event is fired; - if the band cannot fit on a free space on the page, a new page is formed;
- the band and all its objects are displayed on a prepared report page;
- the
AfterPrint
band event is fired; - the
AfterPrint
event of all the band objects is fired.
Printing of the band row occurs as long as there is data in the source. After this, the formation of the report in our case ends. The FinishPage
event of a page is fired and finally - the FinishReport
event of the "Report" object.
So, by using events of different objects, you can control every step of report formation. The key to correct use of events - full understanding of the band printing process, expound in the eleven steps above.
So, a lot of operations can be done, by using only the BeforePrint
band - any change, done to the object, will also be displayed. But in this event, it is not possible to analyze, on which page will the band be printed, if it stretches, because the height of the band will be calculated on step 6. This can be done with the help of the AfterLayout
event in step 7 or AfterPrint
in step 10, but in the latter case, the band is already printed and operations with objects do not give out anything.
In one word, you must clearly state, at what moment each event is fired and use, those, which correspond with the given task.