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

Learn How Easy It Is To Apply Updates With TFDQuery.OnUpdateRecord In Delphi

The OnUpdateRecord sample shows you how to cache the user changes when using read-only dataset and then, how to apply updates on behalf of queries that cannot post updates directly. To this end, the sample uses the OnUpdateRecord event of TFDQuery and the TFDUpdateSQL object.

Location

You can find the CentralizedCachedUpdates sample project at:

  • Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to:
    • Object PascalDatabaseFireDACSamplesComp LayerTFDQueryCachedUpdatesOnUpdateRecord
  • Subversion Repositories:
    • You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

How to Use the Sample

  1. Navigate to the location given above and open Qry_CachedUpdates.dproj.
  2. Press F9 or choose Run > Run.

Files

File in DelphiContains
Qry_CachedUpdates.dproj
Qry_CachedUpdates.dpr
The project itself.
fCachedUpdates.pas
fCachedUpdates.fmx
The main form.

Implementation

Before running the sample, the main components are configured at design time using the Object Inspector as follows:

  • TFDQuery object named qryProducts. This component is used to implement a dataset capable of executing SQL queries. The following setup is needed:
  • The Connection property is configured to specify the FireDAC connection object that is used to connect to a DBMS.
  • The SQL property of qryProducts is set to:

Note: In the RDBMS it has one-to-many relation between Categories and Products tables.

  • The CachedUpdates property is set to True. It means that the dataset will log data changes without immediately applying them to the database.
  • Two TFDUpdateSQL objects named usProducts and usCategories. Both objects are used to provide SQL statements for posting updates from TFDQuery. To this end, the following setup is needed:
  • The ModifySQL property of usProducts is set to:
  • The ModifySQL property of usCategories is set to:
  • TDataSource objects named dsProducts. This component provides an interface between a dataset component and data-aware controls on a form. In this sample, it is used to provide communication between the dataset and the grid where the dataset is displayed. To this end, the following properties are set:
  • The DataSet property of dsProducts is set to qryProducts.
  • The DataSource property of DBGrid1 is set to dsProducts.

For more details, please follow the link to the original post:

http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.TFDQuery.OnUpdateRecord_Sample

Head over and check out the OnUpdateRecord sample source code for Delphi over on GitHub.

See What's New in 12.2 Athens See What's New in 12.2 Athens Dev Days of Summer 2-24

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

Leave a Reply

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

IN THE ARTICLES