#1 2017-01-27 17:01:47

jaclas
Member
Registered: 2014-09-12
Posts: 215

Pass some object as interfaced service method parameter

When I pass object via interfaced service method (with {$M+} and published) then before mORMot deserialize JSON with data of object I must create this object?

example:

service method:
function GetObject(const ObjectId : Integer; out Object : TMyObject);

use of this method:

var
 lObject  : TMyObject;
 //lObject := TMyObject.Create;  <-- without create object I get error on next line
 GetObject(x, lObject);  //<-- error if lObject = nil

mORMot can't autocreate this object?

Offline

#2 2017-01-28 10:20:54

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,669
Website

Re: Pass some object as interfaced service method parameter

The client should create the instances, even for output parameter.
Most of the time it won't be a temporary object but a field.

They will be created on the server side, when running the service implementation.

If you want some transient value, use a record not a class.
You just need to declare it on the stack. No need to call create.

Offline

#3 2017-01-28 18:59:02

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Pass some object as interfaced service method parameter

Thanks for clarification. One more question:

why JSON is different (name quoted) between transfer as object or as record?

See on fields eg. VATID (and others):

send as record (with quotes):

{"VATID":"","PersonKind":76,"PKD":"","PlaceId":"","CommuneId":"","ProductId":268484512,"ProductVersion":0,"ProductReleaseDate":10000,"DemoVersionMode":76,"LastReceivedUUID":"","SystemId":42678,"SystemCodePage":-702306117,"ScreenResolution":-2,"DateOfCommencement":10000}

send as object (without quotes):

{VATID:"87654332",CommuneId:"0",DateOfCommencement:1485632481,LastReceivedUUID:"{3C71F148-5F70-4177-AF94-544E51FDC5D6}",PKD:"pkd",PlaceId:"09",ProductId:1234,ProductReleaseDate:100000,ProductVersion:87675675,ScreenResolution:700,SystemCodePage:987,SystemId:150}

Offline

#4 2017-01-29 08:47:14

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,669
Website

Re: Pass some object as interfaced service method parameter

It depends on the settings.

Offline

Board footer

Powered by FluxBB