<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Ryan Joseph via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> schrieb am Mo., 5. Apr. 2021, 05:58:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Apr 4, 2021, at 2:36 PM, Sven Barth via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank" rel="noreferrer">fpc-pascal@lists.freepascal.org</a>> wrote:<br>
> <br>
> The RTTI streaming relies on *published properties* (and published methods for the event handlers).<br>
<br>
Sorry Sven, I'm not understand what I'm doing wrong. From original example "scale" is a published property right? So FieldAddress only works on published fields, which are not supported unless they are classes/interfaces.<br>
<br>
type<br>
 TSomething = class(TPersistent)<br>
   private<br>
     m_scale: integer;<br>
   published<br>
     property scale: integer read m_scale write m_scale;<br>
 end;<br>
<br>
I have used published properties like this for JSON streaming, i.e.:<br>
<br>
type<br>
  TVectorObject = class(TPersistent)<br>
    private<br>
      components: array[0..2] of integer;<br>
    published<br>
      property x: integer read components[0] write components[0];<br>
      property y: integer read components[1] write components[1];<br>
      property z: integer read components[2] write components[2];<br>
  end;<br>
<br>
which works just fine so I assume I can use the RTTI functions, just not FieldAddress.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Correct. You need to use GetOrdProp and similar from the TypInfo unit or the object oriented variant from the Rtti unit. </div><div dir="auto"><br></div><div dir="auto">Note: you don't need to inherit from TPersistent if you simply want to manually access such properties, setting $M+ before the type (and resetting it afterwards) is enough to enable the published section. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>