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() << Firedac_Comp_Dataset__3::coRestart << Firedac_Comp_Dataset__3::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
ASourcedataset structure into the Self dataset, ifcoStructureis inAOptions, and:- Copies the
ASourcedataset indexes setup into the Self dataset, ifcoIndexesCopyis inAOptions. Otherwise, resets the Self indexes setup, ifcoIndexesResetis inAOptions. - Copies the
ASourcedataset aggregates setup into the Self dataset, ifcoAggregatesCopyis inAOptions. Or resets the Self aggregates setup, ifcoAggregatesResetis inAOptions. - Copies the
ASourcedataset constraints setup into the Self dataset, ifcoConstraintsCopyis inAOptions. Or resets the Self constraints setup, ifcoConstraintsResetis inAOptions.
- Copies the
- Opens the Self dataset, if it is inactive.
- Sets
ASourceto the start, ifsoRestartis inAOptions. - For each record in
ASourcedo:- If
coEditis 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
coAppendis inAOptions, then append a new record to the Self dataset. - If
coDeleteis 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
ASourcefield 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]);