zoukankan      html  css  js  c++  java
  • Delphi 2010 新增功能之: Rtti 单元(4): TRttiRecordType


    下面以 TPoint 为例, 用 TRttiRecordType 读取了结构的信息.

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Memo1: TMemo;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    uses Rtti;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      t: TRttiRecordType;
      f: TRttiField;
    begin
      Memo1.Clear;
      t := TRttiContext.Create.GetType(TypeInfo(TPoint)).AsRecord;
      Memo1.Lines.Add(t.QualifiedName);
      Memo1.Lines.Add(Format('Size: %d', [t.TypeSize]));
      Memo1.Lines.Add(EmptyStr);
    
      Memo1.Lines.Add(Format('字段数: %d', [Length(t.GetFields)]));
      Memo1.Lines.Add(Format('方法数: %d', [Length(t.GetMethods)]));
      Memo1.Lines.Add(Format('属性数: %d', [Length(t.GetProperties)]));
      Memo1.Lines.Add(EmptyStr);
    
      Memo1.Lines.Add('全部字段:');
      for f in t.GetFields do Memo1.Lines.Add(f.ToString);
    end;
    
    end.
    
  • 相关阅读:
    ABP 异常
    Vmware中安装的Ubuntu不能全屏问题解决
    centos7.4 文件权限
    webpack 入门(1)
    webpack(2) 概念
    centos7.4 rpm命令
    centos7.4 which、whereis、locate的使用
    centos7.4 find命令
    centos7.4 lsof用法
    centos7.4 用户和组的管理
  • 原文地址:https://www.cnblogs.com/del/p/1584167.html
Copyright © 2011-2022 走看看