#1 2025-04-30 21:27:31

Esequias
Member
Registered: 2023-06-29
Posts: 6

JSON mORMot2 Delphi 7 Access Violation

JSON mORMot2 Delphi 7 Access Violation in mormot.core.base

function FindNonVoidRawUtf8I(n: PPointerArray; name: pointer; len: TStrLen; count: PtrInt): PtrInt;
line 5:

    if (PStrLen(p1 - _STRLEN)^ = len) and          // same length
       ((ord(p1^) xor ord(p2^)) and $df = 0) then  // same first char

for this code:

Var Data: Variant;
Begin
     TDocVariant.New(Data);
     Data.Sale:= _Obj([]);
     Data.Sale.Id:= '100';
     Data.Sale.Number:= '10';
     Data.Sale.Invoice:= _Obj([]);
     Data.Sale.Invoice.Client:= StringToUtf8('José'); // Access Violation
...

The same code works fine in Delphi 10.2

I understand that I should not use Delphi 7, but I am not allowed to migrate the project to a newer version of Delphi.

I also know that there are other ways to generate the JSON, but in my case if conditions must be added to evaluate at runtime what data to add or not to add to the JSON.

I am grateful for any help you can give me

Offline

#2 2025-04-30 22:15:57

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,005
Website

Re: JSON mORMot2 Delphi 7 Access Violation

Use TDocVariantData instead of late binding.

Offline

#3 2025-05-01 04:43:01

Esequias
Member
Registered: 2023-06-29
Posts: 6

Re: JSON mORMot2 Delphi 7 Access Violation

Thank you so much.

This is the line that generates the access violation in Delphi 7:

Data.Sale.Invoice:= _Obj([]);

And it is solved if it is replaced by this line:

DocVariantData(Data.Sale).O_['Invoice'];

Last edited by Esequias (2025-05-03 05:28:03)

Offline

Board footer

Powered by FluxBB