WebClientdataset yields "No fields found" - but data is available

I have a WebClientConnection + WebClientdataset+WebDataSource+WebDBGrid. Fields are defined at designtime.
The Click of a button executes:

procedure TForm1.TMSFNCEditButton1ButtonClick(Sender: TObject);
begin
  WebClientDataSet1.Active:=false;
  WebClientConnection1.Active:=false;
   WebClientConnection1.URI:='https://www.nutritional-software.at/api/api.php/records/TBLLEBENSMITTEL'+
   '?filter=BEZEICHNUNG,cs,'+TMSFNCEditButton1.Text;
   WebClientConnection1.URI:=WebClientConnection1.URI+'&include=LEBENSMITTELCD,HERKUNFTCD,BEZEICHNUNG';
  WebClientConnection1.Active:=true;
  WebClientDataSet1.Active:=true;
end;

The first click on the button seems to do nothing, the second click show the error and displays the data.

 ERROR
No fields found | fMessage::No fields found FJSError::Error: No fields found fHelpContext::0
at https://www.nutritional-software.at/WebCore/P03/Project1.js [89953:68]

If I remove the WebClientDataSet1.Active:=true; (I have the AutoOpendataSet = true too), the error does not occur.

What am I missing?

Thank you!
Bernd

The code you wrote is correct according to Delphi's logic. But in TMS Web Core you cannot expect WebClientConnection1 to be active just after it is called. Those (setting Active to true) operations are both asynchronous due to JS environment. Use WebClientConnection1AfterConnect event to active WebClientDataSet1.

This asynchronous behavior also exists in other parts of TMS Web Core like creating forms etc. I also recommend searching "await" keyword in the documentation/forum will help porting Delphi logic to web core.

1 Like

Ah, I see. Thanks for that.