problem with await

I'm probably misunderstanding this. I have been using this in my new app, and so far it has been great - much better code flow.

I have one use where I get "uncaught (in promise) object".

The procedure is marked as [async] and it calls back to an interface to check a value.

I have an input and an onchange event

procedure TShopEditForm.ShopRefChange(Sender: TObject);
begin
  if (DSShop.State = dsInsert) and (ShopRef.Text <> FValidatedRef) then
  begin
    CheckWebClient; // checks that the TXDataWebClient has been created
    CheckShopRef;  // this is the [async] call
  end;
end;

The async call is

procedure TShopEditForm.CheckShopRef;
var
  lRetval: TXDataClientResponse;
  lOutcome: Boolean;
  AShopRef: string;
begin
  AShopRef := ShopRef.Text;
  lRetval := await(TXDataClientResponse, FWebClient.RawInvokeAsync(IUTILSVC_CHECK_SHOPREF, [AShopRef]));
  lOutcome := Boolean(TJSObject(lRetval.Result)['value']);
  if lOutcome then
  begin
    FRefStatus := RefUnique;
    FValidatedRef := AShopRef;
    ShopRefWarningLabel.Caption := 'Ok'; //'<i class="fad fa-check"></i>';
    ShopRefWarningLabel.Hint := '';
  end
  else
  begin
    FRefStatus := RefInUse;
    FValidatedRef := '';
    ShopRefWarningLabel.Caption := 'In use'; //'<i class="fad fa-exclamation-triangle"></i>';
    ShopRefWarningLabel.Hint := 'This shop reference is already in use';
  end;
end;

Can anyone put me on the right path? Thanks.

Is FWebClient.RawInvokeAsync returning a promise?

I thought that RawInvoke always returned a promise which is why it had to be handled in an OnSuccess event. I might be misunderstanding this however

RawInvokeAsync is an async method that can be called with await. Everything looks ok. Can you please provide more information? When that error is raised? Runtime? Compile time? Is this easily reproducible on our side?

I can't test it at the moment, but I think this might be a rookie error with the SQL in my XData Server.

1 Like