FFieldMapper is null

I am getting an exception that was making no sense.

I traced it. Its ion this code, unit JSONDataset

function TBaseJSONDataSet.GetFieldData(Field: TField; Buffer: TDatarecord): JSValue;

var
  R : JSValue;

begin
  if State in [dsCalcFields,dsInternalCalc] then
    R:=CalcBuffer.data
  else if (State=dsFilter) then
    R:=FFilterRow
  else if (FEditIdx=Buffer.Bookmark) then
    begin
    if State=dsOldValue then
      R:=Buffer.data
    else
      R:=FEditRow;
    end
  else
    begin
    if State=dsOldValue then
      Exit(Null)
    else
      R:=Buffer.data;
    end;
  Result:=FFieldMapper.GetJSONDataForField(Field,R);   <-------------------
  if isUndefined(Result) then
    Result:=Null;
end;

FFieldmapper is null. What does this mean? What havent I done ?

The origin code is

  edtRegistration.Text := xds.FieldByName (fld_AC_Rego).AsString;

And the debugger shows that TXdataWebDataset has the data and that Rego is not null.

FFieldMapper is created in the dataset.Open method.
Are you trying to use this without having called Open first?

I am using Load after setting a filter. I was setting up 5 of these datasets and then a small timer delay. This worked in Insert mode of the main table. But was failing in View or Edit mode.

On a hunch, I extended my timer and it works.

Is there anything else I can use apart from LoadAsync ? I assume that this halts the "thread" until the dataset is loaded, which is not ideal.

The proper way is to use await with LoadAsync if you do operations after the loading.

Does this freeze the execution of the code though?

On reading the docs, it would seem that if I use Load, it returns right away. But calls Open when its loaded the data. So, could I use AfterOpen event ???

You could indeed use the AfterOpen event to ensure that this code is executed only after the open effectively finished.

Thanks, I just tested it, it seems to work.