#1 2022-09-22 08:57:11

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 238
Website

SetPropsFromText and TArray<...>

Hi,

in Delphi, there is the possibility to declare arrays using TArray<...> rather than array of ..., which has a few advantages.

However, TRttiCustom.SetPropsFromText only handles array of ..., when parsing a string of properties.

When using code such as

  OrigRtti := Rtti.RegisterClass(aOrmClass);
  for var Prop in OrigRtti.Props.List do
      PropText := PropText + ';' + Prop.Name + ':' + Prop.Value.Name;

Prop.Value.Name will return TArray<...> when declared in that way.

Is there a fair chance of getting TRttiCustom.SetPropsFromText to work with TArray<...>, which from a mORMot pov would be the same, as array of ... ?

Regards,
Daniel

Offline

#2 2022-09-22 13:34:16

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

Re: SetPropsFromText and TArray<...>

TArray<..> syntax should already be handled by SetPropsFromText().

See line 7900 and following of mormot.core.rtti.

Offline

#3 2022-09-22 14:58:38

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 238
Website

Re: SetPropsFromText and TArray<...>

Hm, it crashed on me today, I'll give more details tomorrow. Had just shut down my VM. :-D

Thanks,
Daniel

Offline

#4 2022-09-23 09:06:07

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 238
Website

Re: SetPropsFromText and TArray<...>

Here is a simple sample, breaking with TArray<...>, working with array of ...

https://pastebin.com/JyzF67hN

Enable/Disable lines 14&17 to see difference.

Offline

#5 2022-09-23 09:10:05

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 238
Website

Re: SetPropsFromText and TArray<...>

Checking into it (ln 7900)
alen = 6
aname = 'TArray'

so, Typename does not contain the expected 'TArray<TPpCallSecurityRight>, but simply TArray.

Offline

#6 2022-09-23 09:13:49

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 238
Website

Re: SetPropsFromText and TArray<...>

Digging deeper, you call GetNextFieldProp, which in turn only selects alphanumeric and underscores

  while tcIdentifier in tab[P^] do
    inc(P); // go to end of ['_', '0'..'9', 'a'..'z', 'A'..'Z'] chars

Therefore, the <....> part never becomes part of the typename, therefore failing the test in lns 9000+

Regards,
Daniel

Offline

#7 2022-09-23 15:35:06

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

Re: SetPropsFromText and TArray<...>

Offline

#8 2022-09-26 06:36:08

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 238
Website

Re: SetPropsFromText and TArray<...>

While this part works now, I have noticed another small, Delphi specific glitch around that. From the original sample code, I used

Prop.Value.Name

to get the type.
When using TArray it propagate as

TArray<Unitname.Typename.SubTypeName>

Due to including the unit name, FindType will not recognize the Type. Should prop value name be handled specific in that case?

I uploaded example it would generate

SomeStr: UTF8String;Fail:TArray<Decl.TPpCallSecurityRight>;

<-- note the Decl.

Regards,
Daniel

Offline

#9 2022-09-26 08:41:29

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

Re: SetPropsFromText and TArray<...>

The problem is that in mormot.core.rtti the type name is expected to be unique globally.
We could remove the unit name, but if there are several TPpCallSecurityRight types defined, it would only find the first declared, which may not be in Decl...
See https://github.com/synopse/mORMot2/commit/3df95e4a

But it is likely not to work with Delphi specific Typename.SubTypeName type definitions.

Offline

Board footer

Powered by FluxBB