为什么DELPHI的IDE在结构变量的一点后
能列出该结构变量的成员名称和成员类型。

解决方案 »

  1.   

    因为Delphi的IDE利用的是编译信息。就是对于类,RTTI也只存在于published区域。至于{$M+}到底有没有作用,很难说。
      

  2.   

    //记录类型没有RTTI的证据
    type
      TMyClass = class(TComponent)
      private
        FRect: TRect;
        FCount:Integer;
      published
        property Rect: TRect read FRect write FRect; 
        property Count: Integer read FCount write FCount; 
      end;//在Object Inspector看不见Rect
      

  3.   

    去读<<Dissecting MFC>>
      

  4.   

    Delphi 帮助文档里提到RTTI{$M+}时说,
    The $M switch directive controls generation of runtime type information (RTTI). When a class is declared in the {$M+} state, or is derived from a class that was declared in the {$M+} state, the compiler generates runtime type information for fields, methods, and properties that are declared in a published section.
    也就是说,RTTI只对类的Published节下的字段、属性、方法有效。你可以把你的记录定义改成类定义,再用{$M+},应该就OK了。
      

  5.   

    记录类型没有RTTI的证据:
    type
      R_Test = packed record
        higklmn222 : Integer;
      end;
      TMyClass = class(TComponent)
        Fabcdefg: Integer;
      published
        property abcdefg111: Integer read Fabcdefg write Fabcdefg; 
      end;
    在生成的EXE文件中可以找到'abcdefg111'这个字符串(用ultraedit之类的工具打开),但是没有'higklmn222'!即使使用$M+,RTTI中好像也只能访问published的内容,而不能访问其它的成员.
      

  6.   

    看看侯俊杰的《深入浅出mfc》,关于mfc源码分析,有关于实现rtti的原理,虽然是vc的,但是对你也有帮助。
      

  7.   

    之所以IDE可以直接访问所有的成员,我猜是因为有DCU(包括内存中的DCU)文件,才会有那样的功能吧。总之和RTTI不是一回事。
      

  8.   

    首先声明我也不懂,
    但个人觉得应该将记录定义改成类定义后才有可能满足你的要求。
    因为RTTI是专为类而设计的。参看了一些这方面的书籍后。发现它实际上是在存储类的信息时将RTTI的相关信息一起存进去了。在Borland的机制中好像是放在存在虚函数地方的前面。包含了类名,父亲名等相关信息。而存储记录不使用这种方法。所以赞成用: skyweb2k(skyweb) 的解决方法。
      

  9.   

    看看TObject的原代码不就清楚了吗?RTTI的信息都定义在里面呢!!!