Delphi 遍历类中的属性
http://blog.csdn.net/easyboot/article/details/8004954
Delphi 遍历类中的属性

版权声明:本文为博主原创文章,未经博主允许不得转载。
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls,TypInfo;
- type
- TForm1 = class(TForm)
- Button2: TButton;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- {$M+} //如果不用 {$M+} 则需要继承TPersistent
- TTest = class(TObject)
- public
- FName,FSex,FScholl:string;
- published
- property Name :string read FName write FName;
- property Sex :string read FSex write FSex;
- property Scholl :string read FScholl write FScholl;
- end;
- {$M-}
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.Button2Click(Sender: TObject);
- var
- PropCount, I: SmallInt;
- PropList: PPropList;
- PropStr,sValues: string;
- AClass:TTest;
- AStrings:TStrings;
- begin
- AStrings:=TStrings.Create;
- AClass:=TTest.Create;
- AClass.Name:='MyTest';
- AClass.Sex:='Male';
- AClass.Scholl:='Scholl';
- PropCount := GetTypeData(AClass.ClassInfo).PropCount;
- GetPropList(AClass.ClassInfo, PropList);
- for I := 0 to PropCount - 1 do
- begin
- case PropList[I]^.PropType^.Kind of
- tkClass : PropStr := '[Class] ';
- tkMethod : PropStr := '[Method]';
- tkSet : PropStr := '[Set] ';
- tkEnumeration: PropStr := '[Enum] ';
- else
- PropStr := '[Field] ';
- end;
- PropStr := PropStr + PropList[I]^.Name;
- PropStr := PropStr + ': ' + PropList[I]^.PropType^.Name;
- sValues:=GetPropValue(AClass,PropList[I].Name,True);
- ShowMessage(sValues);
- ShowMessage(PropStr);
- end;
- FreeMem(PropList);
- end;
- end.
Delphi 遍历类中的属性的更多相关文章
- Java 遍历类中的属性
public static void testReflect(Object model) throws NoSuchMethodException, IllegalAccessException, I ...
- java中遍历类中的属性、调用getter&setter方法
public static void testReflect(Object model) throws NoSuchMethodException, IllegalAccessException, I ...
- 转载:java 中对类中的属性使用set/get方法的意义和用法
经常看到有朋友提到类似:对类中的属性使用set/get方法的作用?理论的回答当然是封闭性之类的,但是这样对我们有什么作用呢?为什么要这样设计?我直接使用属性名来访问不是更直接,代码更简洁明了吗?下面我 ...
- 尚硅谷面试第一季-11MyBatis中当实体类中的属性名和表中的字段名不一样怎么办
问题: MyBatis中当实体类中的属性名和表中的字段名不一样 ,怎么办 ? 解决方案: 1.写sql语句时起别名 <!-- id属性:必须是接口中方法的方法名 resultType属性:必须是 ...
- 关于System类中out属性 实例化的问题
System类中out属性的声明是这样的: public final static PrintStream out = nullPrintStream(); private static PrintS ...
- 使用反射获取类中的属性(可用于动态返回PO类的列,当做表格的表头)
//利用反射取类中的属性字段 try { Class clazz = Class.forName("houji.bean.model.TaskModel"); Field[] fi ...
- Python 简明教程 --- 20,Python 类中的属性与方法
微信公众号:码农充电站pro 个人主页:https://codeshellme.github.io 与客户保持良好的关系可以使生产率加倍. -- Larry Bernstain 目录 类中的变量称为属 ...
- Java初学者作业——定义英雄类(Hero),英雄类中的属性包括:姓名、攻击力、防御力、生命值和魔法值;方法包括:攻击、介绍。
返回本章节 返回作业目录 需求说明: 定义英雄类(Hero),英雄类中的属性包括:姓名.攻击力.防御力.生命值和魔法值:方法包括:攻击.介绍. 实现思路: 分析类的属性及其变量类型. 分析类的方法及其 ...
- Java初学者作业——定义管理员类(Admin),管理员类中的属性包括:姓名、账号、密码、电话;方法包括:登录、显示自己的信息。
返回本章节 返回作业目录 需求说明: 定义管理员类(Admin),管理员类中的属性包括:姓名.账号.密码.电话:方法包括:登录.显示自己的信息. 实现思路: 分析类的属性及其变量类型. 分析类的方法及 ...
随机推荐
- 出去就餐并且理解Express.js的基本知识
Going out to eat and understanding the basics of Express.js出去就餐并且理解Express.js的基本知识 原文:Going out to e ...
- JAVA中自定义properties文件介绍
Gradle中的使用 1. 使用gradle.properties buid.gradle 和 gradle.properties可以项目使用,在同一个项目中,build.gradle可以直接获取其同 ...
- 028-实现阿里云ESC多FLAT网络
实现类似于阿里云ECS的网络结构,其效果为云主机拥有两块和两个不同的网络,一个网络是用于用于和外网连接,一个用于内网通信,但宿主机上至少有两个网卡,整体配置如下:1.在wmare里给宿主机添加一块网卡 ...
- 树莓派上固定ip
sudo nano /etc/dhcpcd.conf interface eth0 static ip_address=192.168.123.99/24 static routers=192.168 ...
- vim比较文件
横向分割显示: $ vim -o filename1 filename2 纵向分割显示: $ vim -O filename1 filename2 ctl w w 切换文件
- qt配置opengl
cmake 编译opengl,参考https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows cmake configure完成没有错误后,点击g ...
- [AI]cognitive business|cognitive thinking
just watch the cognitive business presentation of IBM CEO Ginni. here is my thoughts in this field : ...
- linux find 用法和常见用例
Linux中find常见用法示例 ·find path -option [ -print ] [ -exec -ok command ] {} \; 本人qq群也有许多 ...
- gperftools尝试
最近在找windows下比较好用的函数时间统计的库,听同事说gperftools是跨平台的,就下载下来尝试了一把.发现它确实实现了windows上可以调用的dll库文件(tcmalloc_minima ...
- bzoj5090 [Lydsy1711月赛]组题 分数规划
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=5090 题解 令 \(s_i\) 表示 \(a_i\) 的前缀和. 那么平均难度系数就是 \[ ...