Best way to show exceptions on TMS Web Core, returned from a XData REST Server Service Operation

Hi Guys

I'm evaluating TMS Web Core.

We've service operations made with XData, and some methods returns list of non entity objects.

We want to show those lists in a DBGrid using a dataset.

So far, we were able to use TWebClientConnection / TWebClientDataSet / TWebDataSource set, but the problem with TWebClientConnection is that the event OnConnectError only provides the ErrorCode, which simply returns 500 in case of a server exception.

The other alternative we tried was using a TXDataWebConnection / TXDataWebClient pair, calling RawInvoke. This way we have access to the error returned by the server, but to show the results in a grid with a dataset, we tried to use a TWebClientDataSet and assign the Rows property on RawInvoke success, but somehow it doesn't work.

The only solution we could find to achieve both goals was to fill a TWebStringGrid manually with the results of RawInvoke, but this is not definitely a good solution.

We are not sure if its worth to try TJQXWebGrid and its DataArray property.

Please take a look at the enclosed demo, any help would be greatly appreciated.

Thanks (68.1 KB)

I'm sorry, the demo attached wasn't correct, uploaded a new one now. Thanks (68.5 KB)

Using XData components (method 2) works fine here. It just needed some fine tuning. First, the XDataWebConnection1 was not active, so I connected it in OnCreate event:

procedure TDataModule1.WebDataModuleCreate(Sender: TObject);
  XDataWebConnection1.Connected := True;

Second, WebClientDataset2 was associated WebClientConnection2 which was active. This way a useless request is made and the dataset gets open. You should set disassociate both components by clearing Connection property of WebClientDataset2 at design time.

Finally, in WebButton2Click event, you need to be sure the dataset is closed before settings Rows:

procedure TForm4.WebButton2Click(Sender: TObject);
    procedure(bResponse: TXDataClientResponse)
      obj: TJSObject;
      val: TJSArray;
      obj:= TJSObject(bResponse.Result);
      val:= TJSArray(TJSObject(obj['value']));
      DataModule1.WebClientDataSet2.Active:= False;

      DataModule1.WebClientDataSet2.Rows:= val;
      DataModule1.WebClientDataSet2.Active:= True;
    procedure(bError: TXDataClientError)
      WebMessageDlg1.ShowDialog(bError.ErrorMessage, mtError, [mbOk]);

And everything should work fine.


Great thanks, it's working now.

Also works loading with TJQXGrid.Data.DataArray, btw

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.