Understanding Events

23.04.2021

Events take place when certain program situations occur. These events can be handled in event procedures initiated by the user.

Using Events

In FlexPro, you can implement event procedures at the database, object class (AnyCursorObject and append AnyDocObject, AnyFolder, AnyFormula, AnyFpObject, AnyValueObject), object or application level.

The ObjectOpened event, for example, occurs at the object and object class level, whereas the DatabaseSavedevent is available at the database and the application level. The DatabaseSaved event for a database occurs after this database has been saved. At the application level, the DatabaseSaved event occurs once one of the open databases has been saved.

For information on how to create event procedures for the various objects, you can view any of the following topics:

  Using Events with the Application or Databases Object

  Using Events with the Database Object

  Using Events with FlexPro Objects

  Using Events with Class Objects

Enabling Events

Use the EnableEvents property of the Application object, you can enable or disable the events.

For example, saving a database with the Save method triggers the BeforeDatabaseSave event. This can be prevented by setting the EnableEvents property to False before you call up the Save method.

Application.EnableEvents = False

ActiveDatabase.Save

Application.EnableEvents = True

By default, events in FlexPro are disabled, i.e. Application.EnableEvents is set to False. You can enable events by setting the EnableEvents property to True or change the default settings in the File > Options dialog box on the System Settings tab and select Enable Macro Events .

Note:   If you are creating an event procedure in an object module for the first time, you will be notified if the events option has been disabled.

Event Types

There are basically two types of events in FlexPro. First, there are events that occur once a certain condition occurs. In this case, the application developer is only notified of the change of condition (e.g. ValueModified). The second type includes those events that can be influenced by the application developer. These events form sequences of up to three events. The sequence appears as follows: It starts with a QueryCancelEventName event, which allows the application developer to decide whether a certain program condition may occur. If this event returns True, FlexPro discontinues processing, triggering the EventNameCancelled event. If the QueryCancelEventName event is not processed or if it returns False , FlexPro will continue processing, triggering the Before event just before the event occurs. Eventually, once the program condition has been reached, the EventName event will be initiated.

The following VBA code describes this logic using the ObjectOpened event as an example:

' The oObject object is opened by double-clicking in the

' list view.

If QueryCancelOpenObject(Object) Then

    OpenObjectCanceled oObject

Else ...

    BeforeOpenObject oObject

    oObject ... ' Object is opened ...

    ObjectOpened oObject

End If

Forwarding Events

In FlexPro, events initiated for an object are not just signaled with this object, they are also forwarded to the template databases and/or parent objects in the object model . Thus, events of similar objects in the templates databases or in parent objects of the project database can be processed simultaneously.

For example, once the database "Data.fpd" has been saved, the following event procedures are executed one after the other, depending on whether or not they exist:

DatabaseSaved event procedure of ThisDatabase of the "Data.FPD" database

DatabaseSaved event procedure of ThisDatabase of the personal template database

DatabaseSaved event procedure of Databases collection of the "Data.FPD" database

DatabaseSaved event procedure of Application object

The first argument of an event is always the object concerned. Therefore, an event procedure to which the event was forwarded will know for which object the event just processed has occurred.

The object documentation in the Reference section will tell you to which objects events are forwarded.

Forwarding Events for FlexPro Objects

Forwarding events is particularly important for FlexPro objects. Since a FlexPro database may include many FlexPro objects for which there is no corresponding object module in the Visual Basic Project Explorer, the best practice is to complete the event procedures for one, several or all FlexPro objects in the class object modules AnyCursorObject, AnyDocObject, AnyFolder, AnyFormula, AnyFpObject and AnyValueObject .

For example, if the ObjectModified event of the FpObject object occurs, the following event procedures are executed one after the other, depending on whether or not they exist:

ObjectModified event procedure of the object concerned

ObjectModified event procedure of AnyFpObject in the database containing the object

ObjectModified event procedure of AnyFpObject in the personal template database

The described event cascading applies to all FlexPro objects.

Share article or send as email:

You might be interested in these articles