You are not logged in.
System Information
- Operating system: Windows
- Processor architecture: x86-64
- Device: Computer
- FPC version: 3.3.1 [2024/06/26] for i386, Trunk 0c745fb257
- mORMot2 version: master 70e2e9ce
Example Project
program project1;
{$ifdef FPC}
{$mode delphi}
{$else}
{$APPTYPE CONSOLE}
{$endif}
{$I mormot.defines.inc}
uses
{$I mormot.uses.inc}
{$IFDEF DCC}System.{$ENDIF}Classes, {$IFDEF DCC}System.{$ENDIF}SysUtils,
mormot.core.base,
mormot.core.rtti,
mormot.core.variants,
mormot.core.json;
type
{$RTTI EXPLICIT PROPERTIES([vcPublished]) FIELDS([vcPublic]) METHODS([])}
TEFloor = packed record
el: WORD;
fl: array of Byte;
end;
TECtrl = packed record
ecid: WORD;
expd: array of Byte;
efl: array of TEFloor;
icod: UTF8String;
pt: array of Integer;
adv: BYTE;
end;
TECtrls = Array of TECtrl;
var
tmp1, tmp2: UTf8String;
ec: TECtrls;
begin
tmp1 := '[{"ecid":12,"expd":[80,17,18],"efl":[{"el":0,"fl":[1,2]},{"el":1,"fl":[4,5]}],"icod":"123456","pt":[1,2,3],"adv":5}]';
DynArrayLoadJson(ec, tmp1, TypeInfo(TECtrls));
WriteLn(tmp1);
tmp2 := DynArraySaveJson(ec, TypeInfo(TECtrls));
WriteLn(tmp2);
if tmp1 = tmp2 then WriteLn('ok')
else WriteLn('failed');
end.
The above programs are compiled with fpc and run as follows.
# fpc project1.pas -Fic:\mORMot2\src -Fuc:\mORMot2\src\core;c:\mORMot2\src\lib -Flc:\mORMot2\static\i386-win32
Free Pascal Compiler version 3.3.1 [2024/06/26] for i386
Copyright (c) 1993-2024 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling project1.pas
Linking project1.exe
895 lines compiled, 0.3 sec, 563504 bytes code, 20004 bytes data
# project1
[{"ecid":12,"expd":[80,17,18],"efl":[{"el":0,"fl":[1,2]},{"el":1,"fl":[4,5]}],"icod":"123456","pt":[1,2,3],"adv":5}]
[]
failed
Relevant 3rd party information
The above program is compiled by delphi and the results are as follows
# dcc32 project1.pas -Ic:\mORMot2\src;c:\mORMot2\static\i386-win32 -Uc:\mORMot2\src\core;c:\mORMot2\src\lib -NSSystem;Winapi
Embarcadero Delphi for Win32 compiler version 36.0
Copyright (c) 1983,2024 Embarcadero Technologies, Inc.
c:\mORMot2\src\mormot.defines.inc(792)
c:\mORMot2\src\mormot.uses.inc(50)
project1.pas(56)
897 lines, 0.11 seconds, 1439256 bytes code, 103032 bytes data.
# project1.exe
[{"ecid":12,"expd":[80,17,18],"efl":[{"el":0,"fl":[1,2]},{"el":1,"fl":[4,5]}],"icod":"123456","pt":[1,2,3],"adv":5}]
[{"ecid":12,"expd":[80,17,18],"efl":[{"el":0,"fl":[1,2]},{"el":1,"fl":[4,5]}],"icod":"123456","pt":[1,2,3],"adv":5}]
ok
I know that using RegisterType and RegisterFromText can solve this problem,
But the latest FPC has supported RTTI record (https://gitlab.com/freepascal.org/fpc/s … sues/40798)
Just request improvements to mORMot2 DynArrayLoadJson in FPC.
May mORMot2 get better and better!
Last edited by idigger (2024-06-27 16:01:04)
Offline
I have just added experimental support for this trunk feature.
Feedback is welcome!
See your https://github.com/synopse/mORMot2/issues/266 entry.
No need to copy everything from github in this forum if you already have enough information there.
Offline
project1.pas adds the following statement before TEFloor = packed record.
{$RTTI EXPLICIT
PROPERTIES([vcPublished])
FIELDS([vcPublic])
METHODS([])}
Recompile and run, everything is fine.
You were amazing.
Thank you for your quick response and quick repair.
Last edited by idigger (2024-06-27 10:37:22)
Offline
Offline
After testing, delphi enables rtti record by default, and fpc is off by default.
Replace {$RTTI EXPLICIT PROPERTIES([vcPublished]) FIELDS([]) PROPERTIES([])} with {$RTTI EXPLICIT METHODS([]) FIELDS([vcPublic]) METHODS([])},
project.pas compiled by delphi and the results also failed.
Offline
yes, {$modeswitch advancedrecords} is not needed.
Offline