7

Consider the following:

TFieldType = class
  fValue: string;
end;

TMainClass = class
private
  Ffield: TFieldType;
public
  function GetValue: string;
end;

In TMainClass.GetValue I'm tryin get values of TMainClass fields:

function TMainClass.GetValue;
begin
  vCtx := TRTTIContext.Create;
  vType := vCtx.GetType(Self.ClassInfo);
  for vField in vType.GetFields do
    vField.GetValue(
        //Here's the trouble, because i don't know how to get the instance
    );

May be there are another ways of getting values of fields which are the instances of another classes?

Johan
  • 74,508
  • 24
  • 191
  • 319
boombastic
  • 85
  • 1
  • 5

1 Answers1

7

You have to pass the instance as the a parameter of GetValue like

vField.GetValue(self);

For a better understanding of Rtti read the remarkable articles about RTTI by Robert Love. For this problem specialy this one about Properties and Fields.

Heinz Z.
  • 1,537
  • 3
  • 14
  • 29
  • Thanks a lot, i've read these articles, but it seems not so attentively. Your answer resolvd my problem. – boombastic Oct 12 '09 at 08:50
  • Second link is same one... wrong link pasted ? I think he ment to paste this one: http://robstechcorner.blogspot.com/2009/09/exploring-trttimember-descendants-in.html – oOo Jan 30 '22 at 12:32