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

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
GrahamDLovell

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck