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

Learn How To Retrieve Data And Manage Cached Updates With TFDMemTable In Delphi

The CachedUpdates sample shows you how to work with the TFDMemTable class. To this end, TFDMemTable retrieves data from a database through TFDTableAdapter and TFDCommand. Then, the sample uses some methods and properties of TFDTableAdapter in order to implement some features related with the management of Cached Updates.

Location

You can find the CachedUpdates sample project at:

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

How to Use the Sample

  1. Navigate to the location given above and open CDS_CachedUpdates.dproj.
  2. Press F9 or choose Run > Run.
  3. Click on the Use Connection Definition combo box and select an option.
    • Modify the tables and interact with the provided buttons.

Files

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

Implementation

This sample uses three main components:

When you run the application, click on the Use Connection Definition combo box and select an option in order to define a connection. When you select an item of the combo box, the Active property is set to True in order to open a dataset and read data from a database. Then, the sample displays a table using a TDBGrid component. Once the TDBGrid is filled, you can interact with the sample. Each of the following buttons implements an OnClick event to do what is described below:

  • The RevertRecord button uses the RevertRecord method to undo changes to the current record and remove it from the dataset changes log.
  • The UndoLastChange button uses the UndoLastChange method to undo the last modification to the dataset records and remove the change from the dataset change log.
  • The CancelUpdates button uses the CancelUpdates method to remove all records from the change log and restore the dataset rows to their prior editing state.
  • The ApplyUpdates button uses the ApplyUpdates method to apply changes for all records in the dataset change journal to the database.

Note: These methods may be used only when the CachedUpdates property is set to True. To check it, select the DataSource1 object attached to the TFDMemTable named cdsOrders and see the CachedUpdates property of the DataSet property on the Object Inspector.

To get more details on this sample, please visit the link below:

http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.TFDMemTable.CachedUpdates_Sample

Head over and check out the full source code for the cached updates TFDMemTable FireDAC sample on the Embarcadero 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