You are not logged in.
The code is as follows
program test;
{$mode delphi}{$H+}
{$I mormot.defines.inc}
uses
{$I mormot.uses.inc}
Windows,
mormot.core.base,
mormot.core.variants;
var
s: UTF8String;
V: Variant;
begin
s := '{"code":200,"msg":"ok"}';
V := _Json(RawUtf8(s));
WriteLn(V.code, V.msg);
end.After compiling with the following command, the program crashed when running. (mormot2.lpk has been rebuilt.)
# c:\fpcbuild\fpc\bin\i386-win32\fpc -FiD:\Borland\mORMot2\src -FuD:\Borland\mORMot2\packages\lazarus\lib\i386-win32 test.lpr
Free Pascal Compiler version 3.3.1 [2026/10/16] for i386
Copyright (c) 1993-2026 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.lpr
Linking test.exe
1352 lines compiled, 0.2 sec, 570096 bytes code, 22244 bytes data
# test
An unhandled exception occurred at $0042E7CC:
EVariantTypeCastError: Could not convert variant of type (Null) into type (AnsiString)
$0042E7CC
$00427F1B
$0042C703
$0040CE6DHowever, after compiling with the following command, the program ran correctly.
# c:\fpcbuild\fpc\bin\i386-win32\fpc -FiD:\Borland\mORMot2\src -FuD:\Borland\mORMot2\src\core test.lpr
Free Pascal Compiler version 3.3.1 [2026/10/16] for i386
Copyright (c) 1993-2026 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.lpr
Linking test.exe
1354 lines compiled, 0.2 sec, 661616 bytes code, 22244 bytes data
# test
200okThe versions of FPC and Lazarus are as follows:
Lazarus 5.99 (rev main_5_99-117-g2130d7edc2) FPC 3.3.1 [2026/10/16] i386-win32-win32/win64
I remember that the programs compiled from previous versions of FPC did not have the aforementioned problems.
This issue caused my project to fail at runtime after being compiled with a newer version of FPC/Lazarus.
Last edited by idigger (2026-10-17 19:15:57)
Offline
It is not clear if it is a mormot issue or a fpc issue....
Confirmed that it is a mORMot issue.
After repeatedly switching between different mormot versions for testing, it was ultimately determined that the issue was caused by commit 835079437d00d5d03e95464221b28df96d9b2dd6(* core: optimized TSynInvokeableVariantType.DispInvoke() 2026-07-06 15:58:25).
Last edited by idigger (2026-10-18 14:52:52)
Offline
mormot2.lpk compiler options level need change to -O1
Offline
Compiling `mormot2.lpk` with `-O1` does indeed help. However, versions prior to commit `835079437d00d5d03e95464221b28df96d9b2dd6` could be compiled using the default `-O3` setting without any runtime errors; therefore, the issue is likely introduced by commit `83507943`.
Offline