When it comes to database applications, you start processing lots of data and events. So, to handle these events properly we can use TFDEventAlerter class to handle the database event notifications.
The general behavior of the events is DBMS-specific and TFDEventAlerter provides a unified way of handling them.
To learn how to utilize this class, we can explore the FireDAC TFDEventAlerter Sample
This sample project shows how to work with database events, and it uses the Use Connection Definition drop-down menu to select a connection definition. If the database supports events, then the application fills the supported event kinds.
- Use Connection Definition drop-down menu:
The menu shows all the connections defined on the file at C:UsersPublic DocumentsEmbarcaderoStudioFireDACFDConnectionsDefs.ini.
If the database supports events, then the application fills the supported event kinds.
Once the connection is defined, the Register events button is enabled to register and start accepting events.
- Register events button:
Once you click Register events, the rest of the buttons are enabled.
- Fire events button:
Click Fire events to trigger the alerts.
When there is an alert, the OnAlert event handler is called and the event name and arguments are shown on the TMemo.
When there are no alerts for a “Timeout” period of time, the OnTimeout event handler is called and the Timeout message appears on the TMemo. The timeout period is set by specifying the Timeout argument of the Options property of the TFDEventAlerter.
The value is set to 1000 ms by default (1 sec).
- Unregister events button: