#1 2019-12-13 20:53:16

VojkoCendak
Member
From: Celje Slovenia
Registered: 2012-09-02
Posts: 93

Using Record Getters and setters in object exception AddRecordJSON

Hi, (latest Mormot and Rio 10.3.2)

Whe we use record in property:

  TAllParkDeviceConfiguration = packed record
    DeviceID: Integer;
    IP: RawUTF8;
    PORT: Integer;
    MODE: Integer;      
    BAR_CLOSE: Integer; 
    TIM_ZAP_CLOSE: Integer;  
    TIMEOUT_PREHOD: Integer; 
    TIMEOUT_ISVALID: Integer; 
    TRIGER_LPR: Integer;  
    TIMEOUT_LPR: Integer; 
    PROVIDER: Integer;      
    GSM_SERVICE: RawUTF8;  
  end;
property MyRecord:TAllParkDeviceConfiguration read getMyRecord write setMyRecord;

it throws : Invalid TJSONSerializer.AddRecordJSON(41541b0e).

But if I use:

property MyRecord:TAllParkDeviceConfiguration  read fMyRecord write fMyRecord ;


We need this because we use Interfaces where get and set have to be defined.

Thank you,
Vojko

Offline

#2 2019-12-13 23:04:08

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

Re: Using Record Getters and setters in object exception AddRecordJSON

The property is from a class?
Record properties are not fully supported yet, since it is something not very stable in Delphi compilers, and not supported in FPC.
Any input is welcome.

As a workaround, you can define a variant published property, then return a TDocVariant content from the record for proper serialization.
Or a RawJSON published property - which may be even a bit more efficient.
Those types would support getters and setters.

Offline

#3 2019-12-17 19:49:29

VojkoCendak
Member
From: Celje Slovenia
Registered: 2012-09-02
Posts: 93

Re: Using Record Getters and setters in object exception AddRecordJSON

I implemented published string property and use RecordSaveJSON and RecordLoadJSON.
Worka perfectly, Thank you

Offline

Board footer

Powered by FluxBB