Data.DB.TDataSet.GetClonedDataSet

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function GetClonedDataSet(WithSettings: Boolean): TDataSet; virtual;

C++

virtual TDataSet* __fastcall GetClonedDataSet(bool WithSettings);

Properties

Type Visibility Source Unit Parent
function public
Data.DB.pas
Data.DB.hpp
Data.DB TDataSet

Description

Creates a new instance of the TDataSet derived class and clones the structure and data of this dataset to the new instance.

Use this method to create a cloned instance of this dataset. The NestedDataSetClass property determines the class type of this cloned dataset.

To control the properties of the cloned dataset, use the boolean parameter WithSettings:

  • WithSettings=true: the cloned dataset inherits the basic settings of this dataset.
  • WithSettings=false: the cloned dataset will use the default settings.

Note
Only the following classes support the cloning procedure:

If the TDataSet derived class does not support cloning, this method returns nil.

Examples

To clarify, consider the following sample code snippets. This sample illustrates how to create a new cloned instance of the TDataSet derived class, and then add the Name field values of the cloned dataset to the Memo component.

Delphi:

var
  FDMemTable1: TFDMemTable;
  Memo1 : TMemo;
  ds: TDataSet;
//...
ds := FDMemTable1.GetClonedDataSet(True);
try
  Memo1.Lines.Clear;
  while not ds.Eof do
  begin
    Memo1.Lines.Add(ds['Name']);
    ds.Next;
  end;
finally
  ds.Free;
end;

C++Builder:

{
        TFDMemTable *FDMemTable1;
        TMemo *Memo1;
        TDataSet *ds;        
// ...
	ds = FDMemTable1->GetClonedDataSet(true);
	__try {
		Memo1->Lines->Clear();
		while (! ds->Eof) {
			Memo1->Lines->Add(ds->FieldValues["Name"]);
			ds->Next();
		}
	}
	__finally {
		delete ds;
	}
}

See Also