Delphi的RTTI(许多参考链接)
2014-04-16 15:44
375 查看
RTTI(RunTime Type Information): 运行时类型信息, 就是在程序运行后也能得到类型(譬如 TButton 类)的信息.
这在早期主要用于 IDE 设计时, 譬如把一个 Button 放到窗体后, 此时我们的程序虽然没有运行, 但在 Delphi 的 IDE 编辑环境中, 这个 Button 已经是在运行状态(要不然IDE怎么才能显示我们要求的TButton呢); 此时我们对 Button 的属性等信息的设置都是通过 RTTI 技术实现的.
但在 Delphi 2007 之前, 能够获取 RTTI 信息是有限的.
Delphi 2009 增加了 ObjAuto 单元、Delphi 2010 增加的 RTTI 单元, 这都可以让程序在运行时对类型有更多掌控(副作用是最后生成的程序越来越大).
/article/6946207.html
/article/6946242.html
-------------------------------------例子1----------------------------------------
Uses Rtti, TypInfo;
procedure TForm1.Button3Click(Sender: TObject);
begin
ShowMessage(GetEnumName(TypeInfo(TFormStyle), Ord(FormStyle)));
end;
主窗体上放2个Label,3个Button,然后
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
PropInfo: PPropInfo;
begin
for I := 0 to ComponentCount-1 do
begin
PropInfo:=GetPropInfo(Components[i].ClassInfo, 'Color');
if PropInfo <> nil then
SetOrdProp(Components[i], PropInfo, clBlue);
end;
end;
参考: http://blog.csdn.net/lailai186/article/details/8823496 http://blog.csdn.net/shuaihj/article/details/6125317 http://blog.csdn.net/shuaihj/article/details/6125321 http://blog.csdn.net/shuaihj/article/details/6125691 http://blog.csdn.net/shuaihj/article/details/6125688 http://blog.csdn.net/shuaihj/article/details/6125713 http://blog.csdn.net/shuaihj/article/details/6125693
这在早期主要用于 IDE 设计时, 譬如把一个 Button 放到窗体后, 此时我们的程序虽然没有运行, 但在 Delphi 的 IDE 编辑环境中, 这个 Button 已经是在运行状态(要不然IDE怎么才能显示我们要求的TButton呢); 此时我们对 Button 的属性等信息的设置都是通过 RTTI 技术实现的.
但在 Delphi 2007 之前, 能够获取 RTTI 信息是有限的.
Delphi 2009 增加了 ObjAuto 单元、Delphi 2010 增加的 RTTI 单元, 这都可以让程序在运行时对类型有更多掌控(副作用是最后生成的程序越来越大).
/article/6946207.html
/article/6946242.html
-------------------------------------例子1----------------------------------------
Uses Rtti, TypInfo;
procedure TForm1.Button3Click(Sender: TObject);
begin
ShowMessage(GetEnumName(TypeInfo(TFormStyle), Ord(FormStyle)));
end;
主窗体上放2个Label,3个Button,然后
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
PropInfo: PPropInfo;
begin
for I := 0 to ComponentCount-1 do
begin
PropInfo:=GetPropInfo(Components[i].ClassInfo, 'Color');
if PropInfo <> nil then
SetOrdProp(Components[i], PropInfo, clBlue);
end;
end;
参考: http://blog.csdn.net/lailai186/article/details/8823496 http://blog.csdn.net/shuaihj/article/details/6125317 http://blog.csdn.net/shuaihj/article/details/6125321 http://blog.csdn.net/shuaihj/article/details/6125691 http://blog.csdn.net/shuaihj/article/details/6125688 http://blog.csdn.net/shuaihj/article/details/6125713 http://blog.csdn.net/shuaihj/article/details/6125693
相关文章推荐
- Delphi系列书籍 118本(全)链接参考
- Altera:PCI Express参考设计和应用笔记(链接)
- [转]Delphi 的RTTI机制浅探
- Delphi实现超级链接
- Delphi调用C#动态链接库DLL(摘自网络)
- nginx 限制ip并发数,nginx限制IP链接数的范例参考
- Delphi 编译/链接过程
- Delphi2010的RTTI增强
- 【新人初试】关于gazebo学习的那些参考链接
- Delphi 2010 新增功能之: Rtti 单元(4): TRttiRecordType
- Delphi里的RTTI与反射(举例换掉FOnChange)
- 网络编程 学习参考的几个链接
- Delphi 的RTTI机制浅探
- *Delphi之DLL知识学习2---静态链接和动态链接
- Delphi 的RTTI机制浅探(转)
- struts2原理及配置参考链接
- CDT源代码阅读参考链接(更新中)
- 2013-C++第13周项目参考解答链接集
- Delphi 的RTTI机制浅探
- DELPHI面向对象参考 (转)