6

次の点を考慮してください。

TFieldType = class
  fValue: string;
end;

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

TMainClass.GetValue では、TMainClass フィールドの値を取得しようとしています。

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
    );

別のクラスのインスタンスであるフィールドの値を取得する別の方法があるでしょうか?

4

1 に答える 1

6

インスタンスを GetValue のパラメーターとして渡す必要があります

vField.GetValue(self);

Rtti をよりよく理解するには、Robert Love によるRTTI に関する注目すべき記事を読んでください。この問題については、Properties と Fieldsについて特別に説明します。

于 2009-10-12T08:43:28.460 に答える