Firedac - Datasnap + Fdmemtable + fkInternalCalc

Asked

Viewed 417 times

0

I’m facing problems with fields fkInternalCalc when migrating from TClientDataSet for TFDMemtable.

We use these fields for data manipulation in memory, but they will not be persisted, this is very useful.

We have an applicationdatasnapand created a generic method to recover aTFDJSONDataSets.

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 theDataSetpassed as parameter does not have in yourFields, one that is configured asfkInternalCalc.

But when that happens, that is, when there is a fieldfkInternalCalc previously created on FDMemtable, when executing the line

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

the error below happens; inserir a descrição da imagem aqui

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

I debug using the.dcus, did not reach a consensus. Someone has already gone through this?

We are using XE7 - Update1 Thank you!

1 answer

1

Good, I got it! Apparently, when there are such fields fkInternalCalc you need to open Dataset, give a Dataset.Open() before Dataset.Appenddata, with this 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;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.