Delphi的RTTI(许多参考链接)

RTTI(RunTime Type Information): 运行时类型信息, 就是在程序运行后也能得到类型(譬如 TButton 类)的信息.

这在早期主要用于 IDE 设计时, 譬如把一个 Button 放到窗体后, 此时我们的程序虽然没有运行, 但在 Delphi 的 IDE 编辑环境中, 这个 Button 已经是在运行状态(要不然IDE怎么才能显示我们要求的TButton呢); 此时我们对 Button 的属性等信息的设置都是通过 RTTI 技术实现的.

但在 Delphi 2007 之前, 能够获取 RTTI 信息是有限的.
Delphi 2009 增加了 ObjAuto 单元、Delphi 2010 增加的 RTTI 单元, 这都可以让程序在运行时对类型有更多掌控(副作用是最后生成的程序越来越大).
http://www.cnblogs.com/del/archive/2009/10/15/1583969.html
http://www.cnblogs.com/del/archive/2008/08/16/1269359.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

原文地址:https://www.cnblogs.com/findumars/p/3668792.html