Client.RawInvoke not well documented

Hi
I get difficulties and it appears document about rawinvoke wasn't updated to fit with current implementation

procedure TForm2.WebButton1Click(Sender: TObject);
  procedure OnResult(Response: TXDataClientResponse);
  being
  end;
   procedure OnError(Response: TXDataClientResponse);
  being
  end;
begin
  XDataWebClient.RawInvoke('IMyService.InfoVersion', [], @OnResult,@OnError);
end;

Here RawInvoke seems with wrong agurments but I don't understand what to pass to

procedure TXDataWebClient.RawInvoke(const OperationId: string;
  Args: array of JSValue; SuccessProc: TXDataClientLoadProc;
  ErrorProc: TXDataClientErrorProc);

With Async mode I get also an error about fact "a constant object can be pass as Var parameter"

Response := await(XDataWebClient.RawInvokeAsync('IMyService.InfoVersion', []));

Please can you clarify how to use xDataWebClient with a raw mode for my own implementation ?
(and update documentation about in Web Applications with TMS Web Core | TMS XData documentation)

Thanks
Sylvain

1 Like

I'm sorry, the code works fine. Actually, I had to fix your code as it has being instead of begin, and the declaration type of Response parameter of OnError procedure is wrong (it should be TXDataClientError, not TXDataClientResposne, according to the documentation).

After I fixed the errors in your code, it compiles fine. This is the tested code:

procedure TForm1.Execute;
var
  Response: TXDataClientResponse;
begin
  Response := await(XDataWebClient1.RawInvokeAsync('IMyService.InfoVersion', []));
end;

procedure TForm1.WebButton1Click(Sender: TObject);

  procedure OnResult(Response: TXDataClientResponse);
  begin
  end;

  procedure OnError(Response: TXDataClientError);
  begin
  end;

begin
  XDataWebClient1.RawInvoke('IMyService.InfoVersion', [], @OnResult,@OnError);
end;

Hi Wagner
I tried your first proposal creating a dedicated execute procedure and I still get the syntax error


with compilation error
image

I tested the other syntax (w OnResult and OnError) and it works fine

That's not a syntax error. That's how async/await should work with Web Core/Pas2Js. If you are using await in a procedure, such procedure (Execute, in this case), should have the async directive. That's exactly what the error message says.

More info here: pas2js AsyncAWait - Free Pascal wiki.

thanks Wagner
I forgot the async directive in procedure definition.

type
  TForm1 = class(TWebForm)
  . . . 
  private
    [async] // << to not forget ;-)
    procedure ExecuteAsync;
  . . .

//------------------------------------------------------------------------------
procedure TForm1.ExecuteAsync;
var
  Response: TXDataClientResponse;
begin
  Response := await(XDataWebClient.RawInvokeAsync('IMyService.InfoVersion', []));
  WebMemoJSON.Lines.Add(Response.ResponseText);
end;

thanks for your patience

S.

1 Like

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