zoukankan      html  css  js  c++  java
  • 了解运行时类型信息(RTTI)

    RTTI需要引用单元TypeInfo

    GetPropInfo 函数用于获得属性的 RTTI 指针 PPropInfo。它有四种重载形式,后面三种重载的实现都是调用第一种形式。AKinds 参数用于限制属性的类型,如果得到的 PPropInfo 不属于指定的类型,则返回 nil。

    function GetPropInfo(TypeInfo: PTypeInfo; const PropName: string): PPropInfo;

    function GetPropInfo(Instance: TObject; const PropName: string;AKinds: TTypeKinds = []): PPropInfo;

    function GetPropInfo(AClass: TClass; const PropName: string;AKinds: TTypeKinds = []): PPropInfo;

    function GetPropInfo(TypeInfo: PTypeInfo; const PropName: string;AKinds: TTypeKinds): PPropInfo;

    //以下代码,循环修改窗体上的Button组件的Capiton
    //方法一:
    procedure TForm1.SetCaption;
    var
      pInfo : PPropInfo;
      i:integer;
    begin
      for i := 0 to Self.ControlCount - 1 do
      begin
        pInfo := GetPropInfo(Self.Controls[i],'Caption');   //GetPropInfo,根据'Caption'字符串,查找Caption属性
        if pInfo <> nil then                             //如果有
          TButton(Self.Controls[i]).Caption:= 'ABC';     //修改Capiton
      end;
    end;
    方法二:
    procedure TForm1.SetCaption;
    var
      pInfo : PPropInfo;
      i:integer;
    begin
      for i := 0 to Self.ControlCount - 1 do
      begin
        pInfo := GetPropInfo(Self.Controls[i],'Caption');
        if pInfo <> nil then
          SetPropValue(Self.Controls[i],'Caption','ABC');
      end;
    end;
    View Code
  • 相关阅读:
    shell编程——循环执行
    ubuntu 设置管理 集锦
    27. 计算FPS
    29 GameProject4(+GUI)
    26. D3D显示文本
    30. D3D特效
    28. GUI
    32. 细节映射
    25. GameProject3
    Direct3D渲染到纹理 (部分转)
  • 原文地址:https://www.cnblogs.com/key-ok/p/3358804.html
Copyright © 2011-2022 走看看