Invalid Pointer Operation - Delphi

1

I added a TClientDataSet (cdsTemp) to my Form screen, fine, and I deployed the fields of that TClientDataSet (cdsTemp) via code, like this:

for i := 0 to (cdsAux.Fields.Count - 1) do cdsTemp.Fields.Add(cdsAux.Fields[i]);

Notice that I'm throwing the fields from cdsAux to cdsTemp, I do not know if it's the right way to do it, but it's the one I found, adapted and it's working.

So far everything is fine and working, but when I run the application it passes the cdsAux fields to the cdsTemp for good, but when I close the form it gives the error "Invalid Pointer Operation". If I comment on the procedure that is doing this procedure of playing the fields from cdsAux to the cdsTemp the error does not happen anymore.

That is, the problem is apparently there, I wonder if I'm forgetting something, if I'm doing something wrong, if someone has already gone through it, etc.

    
asked by anonymous 21.02.2017 / 15:49

1 answer

1

Create the fields as follows (size is an integer variable):

for i := 0 to cdsAux.FieldCount -1 do
begin
  tamanho:= cdsAux.Fields[i].Size;
  if (cdsAux.Fields[i].DataType = ftString) and (tamanho = 0) then
    tamanho:=1
  else
    cdsTemp.FieldDefs.Add(cdsAux.Fields[i].FieldName,
          cdsAux.Fields[i].DataType, tamanho);
end;
    
01.03.2017 / 19:21