You are not logged in.
Good day. I found the following problem when working with sets. Change a directive VER2 and see result.
program Project;
{$APPTYPE CONSOLE}
{$DEFINE VER2}
uses
SysUtils
{$IFnDEF VER2}
,SynCommons
{$ELSE}
,mormot.core.base, mormot.core.json
{$ENDIF}
;
type
TMyEnum = (enOne, enTwo, enThree, enFour, enFive);
TMyEnumPart =enTwo..enFour;
TSetMyEnumPart = set of TMyEnumPart;
var pEnum:PUTF8Char; s:RawUTF8;endofobject:Char;
begin
s:='["enTwo"]';
pEnum := PUTF8Char(s);
GetSetNameValue(TypeInfo(TSetMyEnumPart), pEnum, endofobject);
if pEnum <> nil then
Writeln('Error')
else
Writeln('Success');
readln;
end.
Last edited by Alek (2021-12-13 08:47:08)
Offline
What is documented is that it should follow GetJsonField() behavior, which is to point to the ending #0, not to return nil, in mORMot 2.
In fact, there was a change in respect to mORMot 1, in GetJsonField() returned PDest.
In mORMot 2, it results PDest <> nil, and pointing to ending #0.
And therefore, GetSetNameValue() behaves just as GetJsonField() does now.
So you are right, there was something changed.
I have just modified GetSetNameValue() so that it behaves like in mORMot 1.
But I won't be able to change GetJSonField() behavior, because it would break a lot of new code...
Offline
Thanks for the clarification. But when I ran your a new test, I get an error. I am using BDS 2006.
Offline
In Delphi, it seems that the RTTI is not generated as expected.
With FPC, TMyEnumPart has a dedicated RTTI with proper values.
Whereas on Delphi, the RTTI is incorrect: it points to TMyEnum.
So even if on mORMot 1, it did compile and run, but the value returned by GetSetNameValue() was incorrect, because it pointed on TMyEnum and did not take into account the MinValue index.
My recommendation is to NOT use partial types like TMyEnumPart =enTwo..enFour.
Offline
Ok. I will be use
GetSetNameValue(TypeInfo(TSetMyEnum), pEnum, endofobject);
instead TypeInfo(TSetMyEnumPart), where TSetMyEnum = set of TMyEnum;
And all passes.
Offline
Yes, it is. Everything works perfectly in Delphi and Lazarus
Offline