Enabling and Disabling Cached Updates
Go Up to Using Cached Updates
Cached updates are enabled and disabled through the CachedUpdates
properties of TIBDataSet
, TIBTable
, TIBQuery
, and TStoredProc
. CachedUpdates
is False
by default, meaning that cached updates are not enabled for a dataset.
Client datasets always cache updates. They have no
CachedUpdates
property because you cannot disable cached updates on a client dataset.To use cached updates, set CachedUpdates
to True
, either at design time (through the Object Inspector), or at runtime. When you set CachedUpdates
to True
, the dataset’s OnUpdateRecord
event is triggered if you provide it. For more information about the OnUpdateRecord
event, see Creating an OnUpdateRecord Event Handler.
For example, the following code enables cached updates for a dataset at runtime:
CustomersTable.CachedUpdates := True;
When you enable cached updates, a copy of all records necessary for display and editing purposes is cached in local memory. Users view and edit this local copy of data. Changes, insertions, and deletions are also cached in memory. They accumulate in memory until the current cache of local changes is applied to the database. If changed records are successfully applied to the database, the record of those changes are freed in the cache.
Applying cached updates does not disable further cached updates; it only writes the current set of changes to the database and clears them from memory.
To disable cached updates for a dataset, set CachedUpdates
to False
. If you disable cached updates when there are pending changes that you have not yet applied, those changes are discarded without notification. Your application can test the UpdatesPending
property for this condition before disabling cached updates. For example, the following code prompts for confirmation before disabling cached updates for a dataset:
if (CustomersTable.UpdatesPending) if (Application.MessageBox(“Discard pending updates?”, “Unposted changes”, MB_YES + MB_NO) = IDYES) then CustomersTable.CachedUpdates = False;