Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++DatabaseDelphi

Easily Manage Database Event Notifications In Windows Delphi Apps

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

Overview

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.

Implementation

  • 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.

The Kind argument of the Options property of the TFDEventAlerter is set to the event alerter type or empty to use the default alerter.

Once the connection is defined, the Register events button is enabled to register and start accepting events.

  • Register events button:

To start receiving the event alert, the Register method is called. You can also set the Active property of the TFDEventAlerter to True.

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:

To stop receiving the event alerts, the Unregister method is called by clicking Unregister events. You can also set the Active property of the TFDEventAlerter to False to unable alerts.

Head over and check out the full source code for the FireDAC events sample on GitHub.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

About author

Software Developer | CS(CyberSec) Undergrad at APU Malaysia | Delphi/C++ Builder Enthusiast | Microsoft Learn Student Ambassador | Microsoft Azure Certified

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES