TClientDataSet
is in-memory dataset that can work by itself (as you are doing) or in cooperation with a database session. In order to send all the content of the dataset (all the records) you will need to connect it to a TDatasetProvider
component, by using the property TClientDataSet.ProviderName
.
Since TClientDataSet
(CDS) was originally designed to work in a disconnected way, in order to support multi-tier applications, the connection between the CDS and its provider is not by reference, as it is with TDataSource
referencing a dataset. The ProviderName
property is a string that shows the name of the provider.
Another way is to assign the property TClientDataSet.Provider
if they are both in the same DataModule
, but this will happen by code and not by the ObjectInspector.
TDatasetProvider
needs a dataset that will receive all the pending rows from the CDS. TDatasetProvider
also produces some events that may be used to have a finer grained control over the updates (my preference).
When a CDS has records that were changed and need to be persisted, your call the TClientDataset.UppyUpdates
method, that produces a delta packet (all the records that were inserted, deleted or modified) and send it to the provider, that will handle it in order to persist each of the records.
If no error occur during the update, the provider sends the CDS another version of the delta and it will be reconciled with the current content of the CDS. As a result, the pending status of the rows are cleared for another round of operations.
So, in summary:
- Add a
TDatasetProvider
and connect your CDS to it
- Add another dataset (one that can work with your data server) and connect the provider to it
- Call
cds.ApplyUpdates(0)
when you want to send the CDS delta to the provider
- Read more about
TClientDataset
, TDatasetProvider
and the datasnap in Delphi.