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

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

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: 14,659
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: 430

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: 14,659
Website

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

Not yet..

Offline

#5 2024-06-26 18:03:59

idigger
Member
Registered: 2022-11-05
Posts: 6

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

The latest FPC has supported RTTI record (https://gitlab.com/freepascal.org/fpc/s … sues/40798)

Request improvements to mormot2 DynArrayLoadJson in FPC.

Offline

#6 2024-06-27 07:34:20

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

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

About your
https://github.com/synopse/mORMot2/issues/266

I have added experimental support with
https://github.com/synopse/mORMot2/commit/c0dbef41

Feedback is welcome!

Offline

#7 2024-06-27 10:35:55

idigger
Member
Registered: 2022-11-05
Posts: 6

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

You're amazing. Everything is working on the new mormot2.

Offline

Board footer

Powered by FluxBB