How do I pass an object from aWeb Core Application to an xData Servers?

Hello,

I am trying to pass an object as a parameter on a call to an XData Server function. Are there any examples in the demos on how to do that?

For example; I have a TCustomer object with several fields instead of passing each filed as a parameter to do some processing on the server side and save the processed data.

I know I can respond with an object as long as both client and server share the object definition. But the reverse does not seem, to me, obvious. A quick google search only added to my confusion.

Please, let me know if you need further clarification.

Thank you for your time.

Alan

Here are the guidelines for working with XData objects from Web Core:

I finally got around to dig in to the link you suggested. And I have a very simple question.

Given an Object in the TMS Web Application, say TPerson, how do I serialize that object to send it to the server?

I cannot find the exact unit and method to do so. What would you suggest?

Thanks,

Alan

You don't serialize. You should just send the object directly to the server.

But, if such object is not flagged as "external", it does have internally (in the underlying JavaScript object) several private fields that are not only the fields you declared in the class. So if you send that object, it might fail with the server which will not recognize those fields.

Either use a class declared as external or just manually build a simple TJObject instance and fill its fields.

So you are saying that it should be something like this:

Type
  TPerson = class
  private
    FName: string;
    FBirthDate: TDateTime;
  public
    Name: string read FName write FName;
    BirthDate: TDateTime read FBirthDate;
end;

...
  
// in code I should do something like

  APerson := TPerson.Create;
  APerson.Name := 'john doe';
  Aperson.Birthdate := Now;
  xdAddPerson.RawInvoke('IUserDataService.AddUser', [APerson]);

Or did I miss something?

Thanks!

No, I said it shouldn't be something like that. I mentioned external classes of TJSObject class. References: