<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 3, 2015 at 6:17 AM, Torsten Bonde Christiansen <span dir="ltr"><<a href="mailto:tc@epidata.info" target="_blank">tc@epidata.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
  

    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <font face="monospace">Hi,<br>
      <br>
      What does it take for a class to access a field using
      FieldAddress(...)?<br>
      <br>
      I have tried with both typeinfo on/off ({M+}), placing the field
      in private/protected/public/published<br>
      sections but to no avail.<br>
      <br>
      My simple code is:<br>
      <br>
      TMyObject = class<br>
      private <br>
        FRef: TMyObject;<br>
        procedure SetRef(AValue: TMyObject);<br>
      public<br>
        property Ref: TMyObject read FRef write SetRef;<br>
      end;<br>
      <br>
      <br>
      then i have tried to get the adress in two ways:<br>
      <br>
      AMyObject.FieldAddress('FRef');   //returns nil</font><br>
    <font face="monospace"><font face="monospace">AMyObject.FieldAddress('Ref');   
        //also returns nil</font><br>
      <br>
      If i run my code through debugger, the VMT FieldTable is empty
      suggesting no information is<br>
      created. This happens in all cases of typeinfo on/off and
      differenc sections...<br>
      <br>
      What can i do to make the fieldadress accessible?<br>
      <br>
      Regards,<br>
      Torsten.</font></div></blockquote></div><br clear="all"><div>This method return a field address, eg:</div><div><br></div><div><div>{$M+}</div><div>  TMyObject = class(TObject)</div><div>    FRef: TMyObject;</div><div>  end;</div></div><div><br></div><div>...</div><div><br></div><div><div>var</div><div>  VMyObject: TMyObject;</div><div>  VRef: Pointer;</div><div>begin</div><div>  VMyObject := TMyObject.Create;</div><div>  VRef := VMyObject.FieldAddress('FRef');</div></div><div><br></div><div>If you whant to get a property, use the TypInfo.GetObjectProp function.</div><div><br></div>-- <br><div>Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a></div>
</div></div>