#1 2022-04-19 11:41:21

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 257

M2: different results Delphi/FPC, using RecordLoadJson

Console application with Mormot2 connecting to the same Mysql server using RetrieveIList inside an REST Interface call

The code is the following:

 var     upedia:ilist<TOrmUFpedia>; upedio:TOrmUFpedia;
....
srv.Orm.RetrieveIList(TOrmUFpedia,upedia,'RowID,title,descr,opts');
for upedio in upedia do ..... 

TOrmUFpedia is declared as follows:

  TOrmUFpedia = class(TOrm)
    private
      Ftitle, Fdescr, Fopts: utf8string;
      function Getopts: utf8string;
      procedure Setopts(const Value: utf8string);
    public
      cOpts:Dufoptions;
    published
      property title:utf8string index 500 read Ftitle write Ftitle;
      property descr:utf8string index 500 read Fdescr write Fdescr;
      property opts:utf8string read Getopts write Setopts;
  end;

function TOrmUFpedia.Getopts: utf8string;
begin result:=RecordSaveJson(cOpts,typeinfo(Dufoptions)); end;

procedure TOrmUFpedia.Setopts(const Value: utf8string);
begin if (Value='') or (not RecordLoadJson(cOpts,value,typeinfo(Dufoptions))) then cOpts:=Default(Dufoptions); end; 

where Dufoptions is a record

The code using the above is compiled by both Delphi 11.1 and FPC 3.2.0-r47409 [2022/04/01] for i386, all units are used the same, only project file is different
Compiled executable (32 & 64bit for FPC, 32bit for Delphi 11.1) runs using the same database Mysql 10.6.7

When I access the upedio.opts in for each loop as returned by RetrieveIList ...:
a) In Delphi 11.1,  upedio.opts is returned OK
b) In FPC 3.2 I am getting a "￰DA4AAA==" as content

Does  RecordLoadJson needs records like Dufoptions to be registered somehow in FPC ?

Offline

#2 2022-04-19 12:20:49

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,388
Website

Re: M2: different results Delphi/FPC, using RecordLoadJson

This is documented as such, due to FPC not having the RTTI for records, as Delphi does since Delphi 2010.
On FPC, you need to register the record definition as text at startup.

Check https://synopse.info/files/html/Synopse … ml#TITL_51
and https://synopse.info/files/html/Synopse … #TITLE_244
On mORMot 2, use TRttiJson.RegisterFromText() as registration method.

Offline

#3 2022-04-19 13:08:33

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 257

Re: M2: different results Delphi/FPC, using RecordLoadJson

Thanks a lot. I though it was changed in last versions of FPC.

Offline

#4 2022-04-19 13:45:11

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,388
Website

Re: M2: different results Delphi/FPC, using RecordLoadJson

Not yet..

Offline

Board footer

Powered by FluxBB