TWebClientDataSet ERROR: 'no fields found'

Problem: 'no fields found'
TWeb ClientConnection -> TWeb ClientDataSet are in DataModule

TWebDataSource -> TWebDBGrid in a form

If I get an empty data set from the server, the message 'no field found' appears, if there is data everything works fine. Have tried the DB fields as persistent fields or at runtime with no success.

Error occurs after migrating from 1.9.1.0 to 1.9.8.3.

When you do not add persistent fields, the dataset tries to retrieve field names from the received JSON. If the JSON is empty, it can of course not retrieve fields.
If this can happen, add fields you need via dataset.FieldDefs.

Before I open the DataSet for the first time, I add the required fields as follows.
with WebClientDataSet do
start
with TIntegerField.Create(WebClientDataSet) do
//with TStringField.Create(WebClientDataSet) do
start
Name := WebClientDataSet.Name+sFieldName;
FieldKind := _FieldKind; //fkData, fkCalculated
FieldName := sFieldName;
Size := iFieldSize;
DataSet := WebClientDataSet;
end;
end;

Before opening the DataSet I check if the fields exist and if not they are created. Unfortunately without success, the message 'Fields not found' always comes up.
When I create the fields with the editor it works until I create a field with the type fkCalculated. Then I get the error message 'No Fields found' again. So there must be a connection between the normal fields and the calculated fields.

Use something like:

  WebClientDataSet1.FieldDefs.Clear;
  WebClientDataSet1.FieldDefs.Add('_Species_No',ftString,0);
  WebClientDataSet1.FieldDefs.Add('_Category',ftstring,50);
  WebClientDataSet1.FieldDefs.Add('_Common_Name',ftstring,50);
  WebClientDataSet1.FieldDefs.Add('_Species_Name',ftstring,50);
  WebClientDataSet1.FieldDefs.Add('_Length__cm_',ftInteger,0);
  WebClientDataSet1.FieldDefs.Add('_Length_In',ftString,30);
  WebClientDataSet1.FieldDefs.Add('_Notes',ftString,255);
  WebClientConnection1.Active := true;

If you only use data fields and no calculation fields, it works without any problems. As soon as you add your calculated field to the field list, the error appears. I use the following source code:

             with WebClientDataSet1 do
             begin
               with TStringField.Create(WebClientDataSet1) do
               begin
                 Name := WebClientDataSet.Name+'test';
                 FieldKind := fkCalculated;
                 FieldName := 'test';
                 Size := 50;
                 DataSet := WebClientDataSet1;
               end;
             end;

Cause found:
Due to the empty datasourcet without field information, all field definitions are deleted, including those of the calculation fields. If you only create the fields via FieldDefs or by opening the dataset again, you can no longer create calculation fields. In order to achieve this, the FieldDefs have to be converted into persistent fields and the calculation fields have to be treated additionally.

for i := 0 to WebClientDataset.FieldDefs.Count - 1 do
WebClientDataset.FieldDefs[i].CreateField(NIL);

//CALCFIELDS with Prefix: CALC_
for I := 0 to WebClientDataSet.Fields.Count-1 do
begin
if pos('CALC_', WebClientDataSet.Fields[i].FieldName)=1 then
begin
WebClientDataSet.Fields[i].FieldKind:=fkCalculated;
end;
end;