Firedac - Datasnap + FDMemtable + fkInternalCalc

0

I'm having trouble with fkInternalCalc fields when migrating from TClientDataSet to TFDMemtable .

We use these fields to manipulate in-memory data, but they will not be persisted, this is very useful.

We have a datasnap application and we have created a generic method to recover a TFDJSONDataSets from the server.

procedure TProxyExec.Open(const DataSet: TFDMemTable; Query: String;
const TipoSever: TipoServerDB);
var
   Dados: TFDJSONDataSets;
begin
   try
      GetDataSet(Query,Dados,TipoSever);
      DataSet.Close;
      DataSet.AppendData(TFDJSONDataSetsReader.GetListValue(Dados,0));
   finally
      FreeAndNil(Dados);
   end;
end;

Everything happens as expected when the DataSet passed as a parameter does not have in its Fields , one that is set to fkInternalCalc .

But when this happens, that is, when there is a field fkInternalCalc previously created in FDMemtable , when executing the line

DataSet.AppendData(TFDJSONDataSetsReader.GetListValue(Dados,0));

The error below happens;

Debugger Exception Notification Programa.exe raised exception class
FDException with message [FireDAC] [DatS]-38. Cannot change table
[fdmTabela] structure, when table has rows'.

I debugged using .dcus , I did not reach consensus. Has anyone gone through this?

We're using XE7 - Update1 Thanks!

    
asked by anonymous 06.09.2018 / 19:04

1 answer

0

Good, I discovered! Apparently when there are fields of type fkInternalCalc you need to open the Dataset, give a DataSet.Open () before the DataSet.AppendData, so somehow the fields are prepared and AppendData works correctly. My final generic code looks like this;

procedure TProxyExec.Open(const DataSet: TFDMemTable; Query: String;
const TipoSever: TipoServerDB);
var
   Dados: TFDJSONDataSets;
begin
   try
      GetDataSet(Query,Dados,TipoSever);
      DataSet.Close;
      DataSet.Open() <<<<<<<<<<<<<<
      DataSet.AppendData(TFDJSONDataSetsReader.GetListValue(Dados,0));
   finally
      FreeAndNil(Dados);
   end;
end;
    
06.09.2018 / 20:43