Avatar of GrahamDLovell
GrahamDLovell

asked on 

Creating a blank copy of a TClientDataSet

I have a TClientDataSet, called cdsDiction, which is loaded as binary from a file called Diction.cds. This loads OK.

I have another TClientDataSet, called cdsDictionTemp which is intended to be a blank copy of Diction.cds. I am trying to load this as a copy of Diction.

To do this, I have a procedure:

procedure TfDB.SetUpcdsCopy(cdsOrigin, cdsDest: TClientDataSet);
var
  i: integer;
begin
  cdsDest.Free;
  cdsDest := TClientDataSet.Create(self);
  for I := 0 to cdsOrigin.Fields.Count - 1 do
  begin
    cdsDest.FieldDefs.AddFieldDef;
    cdsDest.FieldDefs.Items[i] := cdsOrigin.FieldDefs.Items[i];
  end;
  cdsDest.CreateDataSet;
  cdsDest.Open;
end;

Open in new window


This is called as follows:
  SetUpcdsCopy(cdsDiction, cdsDictionTemp);

Open in new window


The procedure works OK, and does all the steps, but cdsDictionTemp stays nil.

What have I done wrongly?
DelphiPascal

Avatar of undefined
Last Comment
GrahamDLovell
ASKER CERTIFIED SOLUTION
Avatar of GrahamDLovell
GrahamDLovell

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Delphi
Delphi

Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.

60K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo