One of the methods for expanding reports functionality is handling events occurred when the user works with a report.
An event handler enables the user to execute a specified operation each time the event occurs. For example, on connecting an event handling unit, the following options become available:
Process entered data on-the-fly.
Show confirmation dialog box for executed operation.
Execute additional operation before and after an event occurs.
Show information messages that contain particular information (such as identifier of the changed control, hyperlink type).
Regular reports enable the user to set up handling of the events that occur:
Before opening regular report.
Before and after changing the regular report active sheet.
Before and after calculating a data area (or relational data area), entire regular report or specific report sheet.
Before and after printing and exporting regular report.
Before and after saving changed values of data areas.
On changing value of regular report control.
Before saving regular report, and so on.
Main purpose of connection of application macros and event handlers:
Creating hyperlink triggers. If executing macros contained in the connected objects is required as their operations.
Creating formulas.
Event handling. To handle events, describe a class inherited from the ReportEvents class and redetermine methods that implement the required events.
Signature of the specified macro can contain parameters.
To work with event handling units, execute one of the operations:
Select the Development > Units and Events Handling main menu item.
Click the Units and Events Handling button on the toolbar.
After executing one of the operations the List of Units side panel opens:
Select the existing event handling unit or create a new one.
Open unit in development environment
Besides events handling, a unit can implement custom functions to transform data. If the list of units contains such a unit, custom functions will be available in the function wizard on creating a formula.
To execute the example, create a unit. Add links to the Drawing, Express, Report, and Tab system assemblies.
Sub Main;
Begin
End Sub Main;
Class EventsClass: ReportEvents
...
// Event that occurs after regular report sheet calculation
Public Sub OnAfterRecalcSheet(Sheet: IPrxSheet);
Var
Tab: ITabSheet;
Range: ITabRange;
Style: ITabCellStyle;
Begin
// Get report sheet table
Tab := Sheet As ITabSheet;
// Select cell range for highlightin
Range := Tab.Cells(0, 0, 10, 5);
// Set formatting style for selected range
Style := Range.Style;
// Set cell background fill for selected range with green color
Style.BackgroundBrush := New GxSolidBrush.Create(GxColor.FromName("Green"));
End Sub OnAfterRecalcSheet;
...
End Class EventsClass;
As a result, when the event occurs that follows regular report sheet calculation, background of the A0:F10 cell range is filled with green color.
See also: