FireDAC.Comp.DataSet.TFDDataSet.CopyDataSet

From RAD Studio API Documentation
Jump to: navigation, search

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 ));

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, if coStructure is in AOptions, and:
    • Copies the ASource dataset indexes setup into the Self dataset, if coIndexesCopy is in AOptions. Otherwise, resets the Self indexes setup, if coIndexesReset is in AOptions.
    • Copies the ASource dataset aggregates setup into the Self dataset, if coAggregatesCopy is in AOptions. Or resets the Self aggregates setup, if coAggregatesReset is in AOptions.
    • Copies the ASource dataset constraints setup into the Self dataset, if coConstraintsCopy is in AOptions. Or resets the Self constraints setup, if coConstraintsReset is in AOptions.
  • Opens the Self dataset, if it is inactive.
  • Sets ASource to the start, if soRestart is in AOptions.
  • For each record in ASource do:
    • If coEdit is in AOptions, 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 in AOptions, then append a new record to the Self dataset.
    • If coDelete is in AOptions, if a record has been deleted from ASource, 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.

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]);

See Also