FireDAC.Comp.DataSet.TFDDataSet.CopyDataSet
Delphi
procedure CopyDataSet(ASource: TDataset; AOptions: TFDCopyDataSetOptions = [coRestart, coAppend]);
C++
void __fastcall CopyDataSet(Data::Db::TDataSet* ASource, TFDCopyDataSetOptions AOptions = (TFDCopyDataSetOptions() << TFDCopyDataSetOption::coRestart << TFDCopyDataSetOption::coAppend ));
Contents
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
procedure function |
public | FireDAC.Comp.DataSet.pas FireDAC.Comp.DataSet.hpp |
FireDAC.Comp.DataSet | TFDDataSet |
Description
Copies records from the source dataset to this dataset.
Use the CopyDataSet method to copy the records from the ASource
dataset to this dataset.
The method performs the following steps:
- Copies the
ASource
dataset structure into the Self dataset, ifcoStructure
is inAOptions
, and:- Copies the
ASource
dataset indexes setup into the Self dataset, ifcoIndexesCopy
is inAOptions
. Otherwise, resets the Self indexes setup, ifcoIndexesReset
is inAOptions
. - Copies the
ASource
dataset aggregates setup into the Self dataset, ifcoAggregatesCopy
is inAOptions
. Or resets the Self aggregates setup, ifcoAggregatesReset
is inAOptions
. - Copies the
ASource
dataset constraints setup into the Self dataset, ifcoConstraintsCopy
is inAOptions
. Or resets the Self constraints setup, ifcoConstraintsReset
is inAOptions
.
- Copies the
- Opens the Self dataset, if it is inactive.
- Sets
ASource
to the start, ifsoRestart
is inAOptions
. - For each record in
ASource
do:- If
coEdit
is inAOptions
, then locate the corresponding record in the Self dataset.- Note: CopyDataSet uses the values of the fields of the primary key to find the corresponding value.
- If
coAppend
is inAOptions
, then append a new record to the Self dataset. - If
coDelete
is inAOptions
, if a record has been deleted fromASource
, locate the corresponding record in the Self dataset and delete it.- Note: CopyDataSet uses the values of the fields of the primary key to find the corresponding value.
- Copy all fields, whose names exist in both datasets and which are modifiable. If the
ASource
field is not found in this dataset, then it is skipped. It is important that fields with the same name in both datasets are compatible by data type. The CopyDataSet method does not verify if fields are assignment compatible. - Post the record change and select the next record in
ASource
.
- If
Use coRefresh
instead of coEdit
to change records only in a local cache. Do not post changes to the database. This option can be used to refresh this dataset using records from the ASource
dataset.
This method is similar to assigning values to the Data property. The differences are:
- CopyDataSet can copy from a non-FireDAC dataset. The Data property allows you to copy data only from a FireDAC dataset.
- CopyDataSet works through TDataSet API, firing appropriate events. The Data property works through DatS API; no events are fired.
- CopyDataSet copies only current field values. The Data property copies all record field versions and preserves the row state (inserted, deleted, updated, or unchanged).
- Assigning values to Data is much faster than CopyDataSet.
Example
// copies dataset structure and all records
FDMemTable1.CopyDataSet(Query1, [coStructure, coRestart, coAppend]);