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;

    参考:http://www.cnblogs.com/key-ok/p/3358804.html

  • 相关阅读:
    程序执行并发和并行的理解
    计算机的线程和进程的区别理解,不是编程上的进程和线程
    php单线程理解
    一句话题解(2020.12)
    PE328 Lowest-cost Search
    arc109D
    6908. 【2020.11.30提高组模拟】关灯(light)/loj#3385. 「COCI 2020.11」Svjetlo
    CF1456D. Cakes for Clones
    CF1456C. New Game Plus!
    agc025E
  • 原文地址:https://www.cnblogs.com/findumars/p/4748705.html
Copyright © 2011-2022 走看看