如何枚举接口中的所有字符串属性?

时间:2015-05-13 14:01:41

标签: delphi interface delphi-xe7

我希望(如果可能的话)枚举接口中的所有字符串属性,如下所示:

IXMLDocumentSummaryType = interface(IXMLNode)
    ['{AD394EAD-1253-4CA5-9F0A-76122CB53D88}']
    { Property Accessors }
    function Get_Uid: UnicodeString;
    function Get_RsUid: UnicodeString;
    //etc

    { Methods & Properties }
    property Uid    : UnicodeString read Get_Uid write Set_Uid;
    property RsUid  : UnicodeString read Get_RsUid write Set_RsUid;
    property Meta   : UnicodeString read Get_Meta write Set_Meta;
    property Error  : UnicodeString read Get_Error write Set_Error;
  end;

有很多文本属性,我只对43感兴趣。所以,我在静态数组中有43个名字。

   Fields: array[0..42] of RSummary= (
        (Name: 'RsUid' ; Value: ''),
        (Name: 'GbUid' ; Value: ''),
        etc...
    );

现在我想枚举属性并自动将这些属性的值放在数组中。 我有Delphi XE7。

我试过这个:

var
  C: TRttiContext;
  T: TRttiType;
  F: TRttiField;
  P: TRttiProperty;
begin
  T:= C.GetType(IXMLDocumentSummaryType)   <----- not working

1 个答案:

答案 0 :(得分:3)

接口属性与类属性非常不同。界面只有方法,属性只是糖。

您不会获得接口属性的RTTI,因为没有这样的RTTI。

相关问题