Common Tables

I have some common tables which appear as Lookup Tables for TWebDBLookupCombobox on several forms.

I am placing the TXDataWebDataSet for each one, on the datamodule.

Qs:

  1. Should I place the TWebDatasource on the datamodule as well or is it better on each form its used in?

  2. Will the TXDataWebDataSet cache the small table automatically? Or should I add a TWebClientDataSet?

  3. For now I have it on the form.

    1. I have set the source, KeyField, LinkField and LinkSourceon the TWebDBLookupComboBox
    2. I am doing TWebDatasource.Dataset.open in WebFormCreate event.
    3. I was getting this error

    ERROR
    Uncaught TypeError: Cannot read properties of null (reading 'Open') |
    TypeError: Cannot read properties of null (reading 'Open') at
    Object.WebFormCreate (http://localhost:8000/ops/ops.js:116445:36) at
    Object.cb (http://localhost:8000/ops/ops.js:259:19) at Object.DoCreate (http://localhost:8000/ops/ops.js:41392:40) at Object.Create$5 (http://localhost:8000/ops/ops.js:41946:12) at c.$create (http://localhost:8000/ops/ops.js:359:19) at DoStatusCreate (http://localhost:8000/ops/ops.js:43481:32) at XMLHttpRequest.cb (http://localhost:8000/ops/ops.js:286:21)
    at http://localhost:8000/ops/ops.js [288:50]

    4.So, I am opening the dataset in the datamodule in the event TXDataWebConnectionConnect*. The error has gone. But the Roles dropdown is blank.

I have forgotten something. Any clues?

Irrelevant from XData point of view. You should decide it based on your app architecture. Usually in a Delphi app a datasource is bound to the db controls, so I would in general put one in each form.

What do you mean by cache automatically? If you load the data, the dataset will be open with the data and remains like that until you close it, like any other dataset.

That looks again like the asynchronous nature of Javascript. You need to be aware that everything is asynchronous. The connection is made, only then the lookup datasets should be open,, and only then datasets that depend on it should be open.

I am sure it is. But I cant figure out what I am doing wrong. For now, I have shifted the components to the form.

  • I can pick an Entity from a list, so its connecting.
  • I have added the two fields to the Dataset
  • I can Open the Dataset, its Active
  • But the RecordCount is 0 (it has got records)
    srcRoles: TWebDataSource;
    WebDBLookupComboBox1: TWebDBLookupComboBox;
    xdsRoles: TXDataWebDataSet;
    xdsRolesRef: TIntegerField;
    xdsRolesName: TStringField;


procedure TFViewStaffEdit.WebFormCreate(Sender: TObject);
begin
  HiddenNotification;
  srcRoles.DataSet.Open;
end;

procedure TFViewStaffEdit.XDataClientStaffGetLoad(Response: TXDataClientResponse);
begin
  if srcRoles.Dataset.Active
  then Console_Log ('Active');
  Console_Log ('Records ' + IntToStr (srcRoles.DataSet.RecordCount));
  StaffDataset.Close;
  StaffDataset.SetJsonData(Response.Result);
  StaffDataset.Open;
  StaffDataset.Edit;
end;

Okay, I see I have to call the Load method of the TXDataWebDataSet. What does Open method do then?

I was not able to find online help on it. Or I might have go there faster. :-)

It's described here:

https://doc.tmssoftware.com/biz/xdata/guide/web.html#loading-data-automatically