RTTI 如何动态调用函数和方法?

解决方案 »

  1.   

    RTTI獲取的是運行時類的信息!
    不知你要表達什麼?>
      

  2.   

    那就要你自己解析用户的表达式。然后查找VMT完成任务。
      

  3.   

    RTTI只能访问Published里面的东西
      

  4.   

    去看extlib,我也正在看这个东西,主要是想实现把rtti的信息实现多语言化,嘿嘿,当然主要是中文!
      

  5.   

    to kiboisme(蓝色光芒)
    不!各个域的都行。我的Langine(http://www.silentsea.net/candybox)里就有一个例子。
      

  6.   

    cybercake(数字蛋糕)
    那好,
    我请你写出用RTTI访问 Components[n]的程序来。
      

  7.   

    To cybercake(数字蛋糕)
    随便请你试试这段代码
    var
      P : PPropInfo;
    begin
      P := GetPropInfo(Form1, 'ComponentCount');
      if P<>NIL then Caption := 'AA';
      P := GetPropInfo(Form1, 'Owner');
      if P<>NIL then Caption := 'AA';
    end;
    你看一下你的窗口标题改成AA了吗?
      

  8.   

    To 楼上:对不起,你说的对。我曾经设置过TControl的Font(protected)属性。procedure ApplyFontToControl(AControl : TControl);
      var
        font : TFont;
        v : Cardinal;
      begin
        v := 0;
        if GetOrdPropertyValue(AControl, 'Font', v) then
        begin
          font := TFont(v);
          font.Name := 'XXX';
          //...
        end;
      end;其中的GetOrdPropertyValue如下:function GetOrdPropertyValue(AInstance : TPersistent;
      APropertyName : String; var AValue : Cardinal) : Boolean;
    var
      prop : PPropInfo;
    begin
      Result := False;
      if AInstance = nil then Exit;  prop := GetPropInfo(AInstance, APropertyName);
      Result := (prop <> nil)
        and (prop^.PropType^.Kind in [tkInteger, tkChar, tkEnumeration, tkClass, tkMethod, tkWChar, tkInterface]);
        
      if Result then
        AValue := GetOrdProp(AInstance, APropertyName);
    end;虽然当时成功了,但回想一下是因为代入的参数实际上是有Font(published)属性的控件所致。所以因此看来,RTTI考虑的实际上是实参的类型信息,而不是形参……
      

  9.   

    在rtti中有设置和读取的函数指针和原型!~,但是确实只能对Published中的东西操作!~
    要想作其它事情,自己研究vmt表,在system。pas中有
      

  10.   

    http://borland.mblogger.cn/aiirii/posts/4112.aspx如果英語看不懂,就看代碼也可