If the desire is simply to clone objects, Delphi supports this through the TPersistent.Assign method which is the ancestor of the TComponent class, which serves as the basis for the visual and non-visual components of Delphi.
This method takes the contents of an object (the passed by parameter) into the new one, and would look something like this in the following style
procedure ClonazTable(zTableOriginal: TDataset);
begin
zTableClonada.Assign(zTableOriginal);
end;
Another option is to clone objects through Rtti, traversing the object and copying the data from one to the other. There is a good article on the subject in the magazine CLube Delphi number 113.
However since this component is a database query, the information that is fetched from the database will not be cloned together. To do this you need to copy the entire structure of the dataset to something that exists exclusively in memory, such as a TClientDataset.
To do this, you need to first copy the structure and then the data from the original DataSet to the DataSet in Memory, two of the many options that exist to make this work easier are:
1. TJvMemoryData : A component of the Jedi package (which is free), it has a method that copies the structure of a Dataset to the component, leaving only the work of copying the data.
function CopiarDataSet(zTableOriginal: TDataset): TJvMemoryData;
begin
Result := TJvMemoryData.Create(Application);
**Result.CopyStructure(zTableOriginal);**
zTableOriginal.First;
while not(zTableOriginal.Eof) do
begin
***//Código que copia os dados***
zTableOriginal.Next;
end;
end;
2. TdxMemData : A component of the Developer Express package (which is paid for), it has a method that completely copies the Dataset to a new one.
function CopiarDataSet(zTableOriginal: TDataset): TdxMemData;
begin
Result := TdxMemData.Create(Application);
**Result.CopyFromDataSet(zTableOriginal);**
end;