troubleshooting Question

Creating a blank copy of a TClientDataSet

Avatar of GrahamDLovell
GrahamDLovell asked on
DelphiPascal
1 Comment1 Solution1396 ViewsLast Modified:
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;

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

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

What have I done wrongly?
ASKER CERTIFIED SOLUTION
GrahamDLovell

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros