2009-10-12 9 views
5

は、次の点を考慮TMainClass.GetValueでRTTIを使用してDelphiでアクセスフィールドを取得する方法は?

TFieldType = class 
    fValue: string; 
end; 

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

Iよトライン取得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 
    ); 

のインスタンスであるフィールドの値を取得する別の方法があるかもしれませ別のクラス?あなたはRTTIをより良く理解するために

vField.GetValue(self);

ようGetValueメソッドのパラメータとしてインスタンスを渡す必要が

答えて

6

はロバート・ラブでremarkable articles about RTTIをお読みください。この問題のために、これは約Properties and Fieldsです。

+0

ありがとう、これらの記事を読んだことがありますが、それほど注意深くないようです。あなたの答えは私の問題を解決しました。 – boombastic

関連する問題