| 導購 | 订阅 | 在线投稿
分享
 
 
 

DELPHI中使用RTTI

2006-09-16 05:50:34  編輯來源:互聯網  简体版  手機版  評論  字體: ||
 
 
  运行期类型信息(RTTI)是一种语言特征,能使应用程序在运行时得到关于对象的信息。RTTI是Delphi的组件能够融合到IDE中的关键。它在IDE中不仅仅是一个纯学术的过程。

   由于对象都是从TObject继承下来的,因此,对象都包含一个指向它们的RTTI的指针以及几个内建的方法。下面的表列出了TObject的一些方法,用这些方法能获得某个对象实例的信息。

  

  

   函数

   返回类型

   返回值

  

  

   ClassName( )

   string

   对象的类名

  

  

   ClassType()

   boolean

   对象的类型

  

  

   InheritsFrom

   boolean

   判断对象是否继承于一个指定的类

  

  

   ClassParent()

   TClass

   对象的祖先类型

  

  

   Instancesize()

   word

   对象实例的长度(字节数)

  

  

   ClassInfo()

   Pointer

   指向RTTI的指针

  

  

  第一部分:关于as 和 is

   Object Pascal提供了两个运算符as和is,用它们通过RTTI能对对象进行比较和强制类型转换。

   关键字as是类型转换的一种新的形式。它能把一个基层的对象强制类型转换成它的派生类,如果转换不合法就产生一个异常。假定有一个过程,想让它能够传递任何类型的对象,它应该这样定义:

   Procedure Foo(AnObject :Tobject);

   在这个过程如果要对AnObject进行操作,要把它转换为一个派生对象。假定把AnObject看成是一个TEdit派生类型,并想要改变它所包含的文本,用下列代码: (AnObject as Tedit).text := 'wudi_1982';

   能用比较运算符来判断两个对象是否是相兼容的类型,用is运算符把一个未知的对象和一个已知类型或实例进行比较,确定这个未知对象的属性和行为。例如,在对(AnObject 进行强制类型转换前,确定(AnObject 和TEdit是否指针兼容:

   if (AnObject is Tedit) then

   Tedit(AnObjject).text := 'wudi_1982';

   注意在这个例子中不要再使用as进行强制类型转换,这是因为它要大量使用RTTI,另外还因为,在第一行已经判断Foo就是TEdit,可以通过在第2行进行指针转换来优化。

   这两个操作符最典型的应用我想应该是在程序需要的部分清空窗体上所有edit的text属性

DELPHI中使用RTTI
procedure TForm1.ClearEdit(Acontrl: TWinControl);

DELPHI中使用RTTI
var

DELPHI中使用RTTI
i : integer;

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
for i := 0 to Acontrl.ControlCount-1 do

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
if Acontrl.Controls[i] is TEdit then

DELPHI中使用RTTI
((Acontrl.Controls[i]) as TEdit).Text := '';

DELPHI中使用RTTI
if Acontrl.Controls[i] is TCustomControl then

DELPHI中使用RTTI
ClearEdit( (Acontrl.Controls[i] as TCustomControl))

DELPHI中使用RTTI
end;

DELPHI中使用RTTI
end;

  第二部分:RTTI

   上文中已经多次提到了RTTI,但好像并没有看到RTTI出现。那么RTTI是如何表现自己的呢?你将发现, RTTI至少在两个地方对你有用。第一个地方是DELPHI的IDE,这在前面已提到过。通过RTTI,IDE就会知道你正在使用的对象和组件的任何事情。实际上,不只是RTTI,但为了这个讨论,我们只谈RTTI方面。其实上面的as,is操作都间接的使用了RTTI。

   还是用个例子来演示吧。在观看此例子之时,建议你看看typinfo.pas中的内容(DELPHI安装目录下\source\rtl\common\TypInfo.pas);

   下面的例子主要分为两部分,界面上半部分,主要演示通过rtti来显示用户选择类型的信息。(有3个TListBox)。

   下面的部分主要通过RTTI来完成通过配置信息对控件进行属性的赋值操作,这里将演示文本类型和事件类型的赋值。

   窗体文件如下:代码如下:

DELPHI中使用RTTI
object Form1: TForm1

DELPHI中使用RTTI
Left = 150

DELPHI中使用RTTI
Top = 161

DELPHI中使用RTTI
Width = 639

DELPHI中使用RTTI
Height = 372

DELPHI中使用RTTI
Caption = 'Form1'

DELPHI中使用RTTI
Color = clBtnFace

DELPHI中使用RTTI
Font.Charset = DEFAULT_CHARSET

DELPHI中使用RTTI
Font.Color = clWindowText

DELPHI中使用RTTI
Font.Height = -11

DELPHI中使用RTTI
Font.Name = 'Tahoma'

DELPHI中使用RTTI
Font.Style = []

DELPHI中使用RTTI
OldCreateOrder = False

DELPHI中使用RTTI
OnCreate = FormCreate

DELPHI中使用RTTI
PixelsPerInch = 96

DELPHI中使用RTTI
TextHeight = 13

DELPHI中使用RTTI
object Panel1: TPanel

DELPHI中使用RTTI
Left = 0

DELPHI中使用RTTI
Top = 0

DELPHI中使用RTTI
Width = 631

DELPHI中使用RTTI
Height = 185

DELPHI中使用RTTI
Align = alTop

DELPHI中使用RTTI
TabOrder = 0

DELPHI中使用RTTI
object GroupBox1: TGroupBox

DELPHI中使用RTTI
Left = 1

DELPHI中使用RTTI
Top = 1

DELPHI中使用RTTI
Width = 185

DELPHI中使用RTTI
Height = 183

DELPHI中使用RTTI
Align = alLeft

DELPHI中使用RTTI
Caption = '在这里选择要查看类型的信息'

DELPHI中使用RTTI
TabOrder = 0

DELPHI中使用RTTI
object ListBox1: TListBox

DELPHI中使用RTTI
Left = 2

DELPHI中使用RTTI
Top = 15

DELPHI中使用RTTI
Width = 181

DELPHI中使用RTTI
Height = 166

DELPHI中使用RTTI
Align = alClient

DELPHI中使用RTTI
ItemHeight = 13

DELPHI中使用RTTI
TabOrder = 0

DELPHI中使用RTTI
OnClick = ListBox1Click

DELPHI中使用RTTI
end

DELPHI中使用RTTI
end

DELPHI中使用RTTI
object GroupBox2: TGroupBox

DELPHI中使用RTTI
Left = 368

DELPHI中使用RTTI
Top = 1

DELPHI中使用RTTI
Width = 262

DELPHI中使用RTTI
Height = 183

DELPHI中使用RTTI
Align = alRight

DELPHI中使用RTTI
Caption = '属性信息'

DELPHI中使用RTTI
TabOrder = 1

DELPHI中使用RTTI
object ListBox3: TListBox

DELPHI中使用RTTI
Left = 2

DELPHI中使用RTTI
Top = 15

DELPHI中使用RTTI
Width = 258

DELPHI中使用RTTI
Height = 166

DELPHI中使用RTTI
Align = alClient

DELPHI中使用RTTI
ItemHeight = 13

DELPHI中使用RTTI
TabOrder = 0

DELPHI中使用RTTI
end

DELPHI中使用RTTI
end

DELPHI中使用RTTI
object GroupBox3: TGroupBox

DELPHI中使用RTTI
Left = 186

DELPHI中使用RTTI
Top = 1

DELPHI中使用RTTI
Width = 182

DELPHI中使用RTTI
Height = 183

DELPHI中使用RTTI
Align = alClient

DELPHI中使用RTTI
Caption = '基本信息'

DELPHI中使用RTTI
TabOrder = 2

DELPHI中使用RTTI
object ListBox2: TListBox

DELPHI中使用RTTI
Left = 2

DELPHI中使用RTTI
Top = 15

DELPHI中使用RTTI
Width = 178

DELPHI中使用RTTI
Height = 166

DELPHI中使用RTTI
Align = alClient

DELPHI中使用RTTI
ItemHeight = 13

DELPHI中使用RTTI
TabOrder = 0

DELPHI中使用RTTI
end

DELPHI中使用RTTI
end

DELPHI中使用RTTI
end

DELPHI中使用RTTI
object TPanel

DELPHI中使用RTTI
Left = 0

DELPHI中使用RTTI
Top = 185

DELPHI中使用RTTI
Width = 631

DELPHI中使用RTTI
Height = 157

DELPHI中使用RTTI
Align = alClient

DELPHI中使用RTTI
TabOrder = 1

DELPHI中使用RTTI
object Panel2: TPanel

DELPHI中使用RTTI
Left = 1

DELPHI中使用RTTI
Top = 1

DELPHI中使用RTTI
Width = 230

DELPHI中使用RTTI
Height = 155

DELPHI中使用RTTI
Align = alLeft

DELPHI中使用RTTI
TabOrder = 0

DELPHI中使用RTTI
object Label2: TLabel

DELPHI中使用RTTI
Left = 10

DELPHI中使用RTTI
Top = 8

DELPHI中使用RTTI
Width = 84

DELPHI中使用RTTI
Height = 13

DELPHI中使用RTTI
Caption = '要修改的控件名'

DELPHI中使用RTTI
end

DELPHI中使用RTTI
object Label3: TLabel

DELPHI中使用RTTI
Left = 8

DELPHI中使用RTTI
Top = 32

DELPHI中使用RTTI
Width = 72

DELPHI中使用RTTI
Height = 13

DELPHI中使用RTTI
Caption = '修改的属性名'

DELPHI中使用RTTI
end

DELPHI中使用RTTI
object Label4: TLabel

DELPHI中使用RTTI
Left = 8

DELPHI中使用RTTI
Top = 64

DELPHI中使用RTTI
Width = 72

DELPHI中使用RTTI
Height = 13

DELPHI中使用RTTI
Caption = '将属性修改为'

DELPHI中使用RTTI
end

DELPHI中使用RTTI
object edComName: TEdit

DELPHI中使用RTTI
Left = 104

DELPHI中使用RTTI
Top = 5

DELPHI中使用RTTI
Width = 78

DELPHI中使用RTTI
Height = 21

DELPHI中使用RTTI
TabOrder = 0

DELPHI中使用RTTI
Text = 'label1'

DELPHI中使用RTTI
end

DELPHI中使用RTTI
object edPproName: TEdit

DELPHI中使用RTTI
Left = 104

DELPHI中使用RTTI
Top = 32

DELPHI中使用RTTI
Width = 81

DELPHI中使用RTTI
Height = 21

DELPHI中使用RTTI
TabOrder = 1

DELPHI中使用RTTI
Text = 'caption'

DELPHI中使用RTTI
end

DELPHI中使用RTTI
object edValue: TEdit

DELPHI中使用RTTI
Left = 104

DELPHI中使用RTTI
Top = 56

DELPHI中使用RTTI
Width = 81

DELPHI中使用RTTI
Height = 21

DELPHI中使用RTTI
TabOrder = 2

DELPHI中使用RTTI
Text = '12345'

DELPHI中使用RTTI
end

DELPHI中使用RTTI
object btnInit: TButton

DELPHI中使用RTTI
Left = 8

DELPHI中使用RTTI
Top = 104

DELPHI中使用RTTI
Width = 75

DELPHI中使用RTTI
Height = 25

DELPHI中使用RTTI
Caption = '初始化'

DELPHI中使用RTTI
TabOrder = 3

DELPHI中使用RTTI
OnClick = btnInitClick

DELPHI中使用RTTI
end

DELPHI中使用RTTI
object btnModify: TButton

DELPHI中使用RTTI
Left = 104

DELPHI中使用RTTI
Top = 104

DELPHI中使用RTTI
Width = 75

DELPHI中使用RTTI
Height = 25

DELPHI中使用RTTI
Caption = '修改'

DELPHI中使用RTTI
TabOrder = 4

DELPHI中使用RTTI
OnClick = btnModifyClick

DELPHI中使用RTTI
end

DELPHI中使用RTTI
end

DELPHI中使用RTTI
object Panel3: TPanel

DELPHI中使用RTTI
Left = 231

DELPHI中使用RTTI
Top = 1

DELPHI中使用RTTI
Width = 399

DELPHI中使用RTTI
Height = 155

DELPHI中使用RTTI
Align = alClient

DELPHI中使用RTTI
TabOrder = 1

DELPHI中使用RTTI
object GroupBox4: TGroupBox

DELPHI中使用RTTI
Left = 1

DELPHI中使用RTTI
Top = 1

DELPHI中使用RTTI
Width = 397

DELPHI中使用RTTI
Height = 153

DELPHI中使用RTTI
Align = alClient

DELPHI中使用RTTI
Caption = '被修改的控件'

DELPHI中使用RTTI
TabOrder = 0

DELPHI中使用RTTI
object Label1: TLabel

DELPHI中使用RTTI
Left = 16

DELPHI中使用RTTI
Top = 32

DELPHI中使用RTTI
Width = 28

DELPHI中使用RTTI
Height = 13

DELPHI中使用RTTI
Caption = 'label1'

DELPHI中使用RTTI
end

DELPHI中使用RTTI
object BitBtn1: TBitBtn

DELPHI中使用RTTI
Left = 8

DELPHI中使用RTTI
Top = 64

DELPHI中使用RTTI
Width = 75

DELPHI中使用RTTI
Height = 25

DELPHI中使用RTTI
Caption = 'BitBtn1'

DELPHI中使用RTTI
TabOrder = 0

DELPHI中使用RTTI
end

DELPHI中使用RTTI
end

DELPHI中使用RTTI
end

DELPHI中使用RTTI
end

DELPHI中使用RTTI
end

DELPHI中使用RTTI


DELPHI中使用RTTI
DELPHI中使用RTTI
...{

DELPHI中使用RTTI
作者:wudi_1982

DELPHI中使用RTTI
联系方式:wudi_1982@hotmail.com

DELPHI中使用RTTI
转载请注明出处

DELPHI中使用RTTI
}

DELPHI中使用RTTI
unit main;

DELPHI中使用RTTI


DELPHI中使用RTTI
interface

DELPHI中使用RTTI


DELPHI中使用RTTI
uses

DELPHI中使用RTTI
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,

DELPHI中使用RTTI


DELPHI中使用RTTI
Forms,

DELPHI中使用RTTI
Dialogs,typinfo, StdCtrls, ExtCtrls, Buttons;

DELPHI中使用RTTI


DELPHI中使用RTTI
type

DELPHI中使用RTTI
InsertCom = record

DELPHI中使用RTTI
Name : string; //要修改属性的组件名

DELPHI中使用RTTI
PproName : string;//要修改控件的属性名

DELPHI中使用RTTI
MethodName :string;//要修改or添加给控件的事件名

DELPHI中使用RTTI
text : string; //属性值,这里修改的是string类型的数值

DELPHI中使用RTTI
end;

DELPHI中使用RTTI
TForm1 = class(TForm)

DELPHI中使用RTTI
Panel1: TPanel;

DELPHI中使用RTTI
GroupBox1: TGroupBox;

DELPHI中使用RTTI
ListBox1: TListBox;

DELPHI中使用RTTI
GroupBox2: TGroupBox;

DELPHI中使用RTTI
GroupBox3: TGroupBox;

DELPHI中使用RTTI
ListBox2: TListBox;

DELPHI中使用RTTI
ListBox3: TListBox;

DELPHI中使用RTTI
Panel2: TPanel;

DELPHI中使用RTTI
edComName: TEdit;

DELPHI中使用RTTI
Label2: TLabel;

DELPHI中使用RTTI
Label3: TLabel;

DELPHI中使用RTTI
edPproName: TEdit;

DELPHI中使用RTTI
Label4: TLabel;

DELPHI中使用RTTI
edValue: TEdit;

DELPHI中使用RTTI
Panel3: TPanel;

DELPHI中使用RTTI
btnInit: TButton;

DELPHI中使用RTTI
btnModify: TButton;

DELPHI中使用RTTI
GroupBox4: TGroupBox;

DELPHI中使用RTTI
Label1: TLabel;

DELPHI中使用RTTI
BitBtn1: TBitBtn;

DELPHI中使用RTTI


DELPHI中使用RTTI
procedure FormCreate(Sender: TObject);

DELPHI中使用RTTI
procedure ListBox1Click(Sender: TObject);

DELPHI中使用RTTI
procedure btnInitClick(Sender: TObject);

DELPHI中使用RTTI
procedure btnModifyClick(Sender: TObject);

DELPHI中使用RTTI
private

DELPHI中使用RTTI
TestCom : InsertCom;

DELPHI中使用RTTI
procedure MyClick(Sender : TObject); //给控件添加onclick事件

DELPHI中使用RTTI
public

DELPHI中使用RTTI
DELPHI中使用RTTI
...{ Public declarations }

DELPHI中使用RTTI
end;

DELPHI中使用RTTI


DELPHI中使用RTTI
var

DELPHI中使用RTTI
Form1: TForm1;

DELPHI中使用RTTI


DELPHI中使用RTTI
implementation

DELPHI中使用RTTI


DELPHI中使用RTTI
DELPHI中使用RTTI
...{$R *.dfm}

DELPHI中使用RTTI


DELPHI中使用RTTI
function CreateClass(const AClassName : string):TObject;//根据名字生成

DELPHI中使用RTTI
var

DELPHI中使用RTTI
tm : TObject;

DELPHI中使用RTTI
t : TFormClass;

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
t := TFormClass(FindClass(AClassName));

DELPHI中使用RTTI
tm := t.Create(nil);

DELPHI中使用RTTI
Result := tm;

DELPHI中使用RTTI
end;

DELPHI中使用RTTI


DELPHI中使用RTTI
procedure GetBaseClassInfo(AClass : TObject;AStrings : TStrings); //获

DELPHI中使用RTTI


DELPHI中使用RTTI
得类型的基本信息

DELPHI中使用RTTI
var

DELPHI中使用RTTI
classTypeInfo : PTypeInfo;

DELPHI中使用RTTI
ClassDataInfo : PTypeData;

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
classTypeInfo := AClass.ClassInfo;

DELPHI中使用RTTI
ClassDataInfo := GetTypeData(classTypeInfo);

DELPHI中使用RTTI
with AStrings do

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
Add(Format('name is :%s',[classTypeInfo.Name]));

DELPHI中使用RTTI
Add(format('type kind is :%s',[GetEnumName(TypeInfo

DELPHI中使用RTTI


DELPHI中使用RTTI
(TTypeKind),integer(classTypeInfo.Kind))]));

DELPHI中使用RTTI
Add(Format('in : %s',[ClassDataInfo.UnitName]));

DELPHI中使用RTTI
end;

DELPHI中使用RTTI
end;

DELPHI中使用RTTI


DELPHI中使用RTTI
procedure GetBaseClassPro(AClass : TObject;Astrings : TStrings); //获

DELPHI中使用RTTI


DELPHI中使用RTTI
得属性信息

DELPHI中使用RTTI
var

DELPHI中使用RTTI
NumPro : integer; //用来记录事件属性的个数

DELPHI中使用RTTI
Pplst : PPropList; //存放属性列表

DELPHI中使用RTTI
Classtypeinfo : PTypeInfo;

DELPHI中使用RTTI
classDataInfo: PTypeData;

DELPHI中使用RTTI
i : integer;

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
Classtypeinfo := AClass.ClassInfo;

DELPHI中使用RTTI
classDataInfo := GetTypeData(Classtypeinfo);

DELPHI中使用RTTI
if classDataInfo.PropCount <> 0 then

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
//分配空间

DELPHI中使用RTTI
GetMem(Pplst,sizeof(PpropInfo)*classDataInfo.PropCount);

DELPHI中使用RTTI
try

DELPHI中使用RTTI
//获得属性信息到pplst

DELPHI中使用RTTI
GetPropInfos(AClass.ClassInfo,Pplst);

DELPHI中使用RTTI
for I := 0 to classDataInfo.PropCount - 1 do

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
if Pplst[i]^.PropType^.Kind <> tkMethod then

DELPHI中使用RTTI
//这里过滤掉了事件属性

DELPHI中使用RTTI
Astrings.Add(Format('%s:%s',[Pplst[i]^.Name,Pplst[i]

DELPHI中使用RTTI


DELPHI中使用RTTI
^.PropType^.Name]));

DELPHI中使用RTTI
end;

DELPHI中使用RTTI
//获得事件属性

DELPHI中使用RTTI
NumPro := GetPropList(AClass.ClassInfo,[tkMethod],Pplst);

DELPHI中使用RTTI
if NumPro <> 0 then

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
//给列表添加一些标志

DELPHI中使用RTTI
Astrings.Add('');

DELPHI中使用RTTI
Astrings.Add('-----------EVENT-----------');

DELPHI中使用RTTI
Astrings.Add('');

DELPHI中使用RTTI
for i := 0 to NumPro - 1 do //获得事件属性的列表

DELPHI中使用RTTI
Astrings.Add(Format('%s:%s',[Pplst[i]^.Name,Pplst[i]

DELPHI中使用RTTI


DELPHI中使用RTTI
^.PropType^.Name]));

DELPHI中使用RTTI
end;

DELPHI中使用RTTI
finally

DELPHI中使用RTTI
FreeMem(Pplst,sizeof(PpropInfo)*classDataInfo.PropCount);

DELPHI中使用RTTI
end;

DELPHI中使用RTTI
end;

DELPHI中使用RTTI
end;

DELPHI中使用RTTI


DELPHI中使用RTTI


DELPHI中使用RTTI
procedure TForm1.btnInitClick(Sender: TObject);

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
//修改label1的caption属性为12345

DELPHI中使用RTTI
TestCom.Name := edComName.Text;

DELPHI中使用RTTI
TestCom.PproName := edPproName.Text;

DELPHI中使用RTTI
TestCom.text := edValue.Text;

DELPHI中使用RTTI
TestCom.MethodName := 'OnClick';

DELPHI中使用RTTI
btnModify.Enabled := true;

DELPHI中使用RTTI
end;

DELPHI中使用RTTI


DELPHI中使用RTTI
procedure TForm1.btnModifyClick(Sender: TObject);

DELPHI中使用RTTI
var

DELPHI中使用RTTI
pp : PPropInfo;

DELPHI中使用RTTI
obj : TComponent;

DELPHI中使用RTTI
a : TMethod;

DELPHI中使用RTTI
tm : TNotifyEvent;

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
obj := FindComponent(TestCom.Name);//通过名字查找此控件

DELPHI中使用RTTI
if not Assigned(obj) then exit; //如果没有则退出

DELPHI中使用RTTI
//通过getPropInfo获得指定控件的属性信息,注意,这里只能获得那些公开

DELPHI中使用RTTI


DELPHI中使用RTTI
了的属性

DELPHI中使用RTTI
pp := GetPropInfo(obj.ClassInfo,TestCom.PproName);

DELPHI中使用RTTI
if Assigned(pp) then

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
//根据kind判断类型是否为string类型

DELPHI中使用RTTI
case pp^.PropType^.Kind of

DELPHI中使用RTTI
//这里使用setStrProp来为string类型的属性赋值,对起来类型的赋值

DELPHI中使用RTTI


DELPHI中使用RTTI
,请参考TypInfo.pas

DELPHI中使用RTTI
tkString,tkLString,tkWString : SetStrProp

DELPHI中使用RTTI


DELPHI中使用RTTI
(obj,TestCom.PproName,TestCom.text);

DELPHI中使用RTTI
end;

DELPHI中使用RTTI
//给要修改的控件添加onClick事件,

DELPHI中使用RTTI
pp := GetPropInfo(obj.ClassInfo,TestCom.MethodName);

DELPHI中使用RTTI
if Assigned(pp) then

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
if pp^.PropType^.Kind = tkMethod then

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
tm := MyClick;

DELPHI中使用RTTI
//Tmethod的code为函数地址,你也可以通过MethodAddress方法获得

DELPHI中使用RTTI
a.Code := @tm;

DELPHI中使用RTTI
a.Data := Self;

DELPHI中使用RTTI
//对时间赋值

DELPHI中使用RTTI
SetMethodProp(obj,TestCom.MethodName,a);

DELPHI中使用RTTI
end;

DELPHI中使用RTTI
end;

DELPHI中使用RTTI
end;

DELPHI中使用RTTI
end;

DELPHI中使用RTTI


DELPHI中使用RTTI
procedure TForm1.FormCreate(Sender: TObject);

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
btnModify.Enabled := false;

DELPHI中使用RTTI
//给listbox1添加一些类型的类名

DELPHI中使用RTTI
with ListBox1.Items do

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
Add('TApplication');

DELPHI中使用RTTI
Add('TEdit');

DELPHI中使用RTTI
Add('TButton');

DELPHI中使用RTTI
Add('Tmemo');

DELPHI中使用RTTI
Add('TForm');

DELPHI中使用RTTI
end;

DELPHI中使用RTTI


DELPHI中使用RTTI
end;

DELPHI中使用RTTI


DELPHI中使用RTTI
procedure TForm1.ListBox1Click(Sender: TObject);

DELPHI中使用RTTI
var

DELPHI中使用RTTI
t : TObject;

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
//当在类型列表中选择一个类型并用鼠标单击后,分别得到它的属性信息和

DELPHI中使用RTTI


DELPHI中使用RTTI
基本信息

DELPHI中使用RTTI
ListBox2.Clear;

DELPHI中使用RTTI
ListBox3.Clear;

DELPHI中使用RTTI
t := CreateClass(ListBox1.Items[ListBox1.ItemIndex]);

DELPHI中使用RTTI
try

DELPHI中使用RTTI
GetBaseClassInfo(t,ListBox2.Items);

DELPHI中使用RTTI
GetBaseClassPro(t,ListBox3.Items);

DELPHI中使用RTTI
finally

DELPHI中使用RTTI
t.Free;

DELPHI中使用RTTI
end;

DELPHI中使用RTTI
end;

DELPHI中使用RTTI


DELPHI中使用RTTI
procedure TForm1.MyClick(Sender: TObject);

DELPHI中使用RTTI
begin

DELPHI中使用RTTI
//给指定控件添加的一个方法

DELPHI中使用RTTI
ShowMessage('wudi_1982');

DELPHI中使用RTTI
end;

DELPHI中使用RTTI


DELPHI中使用RTTI
initialization

DELPHI中使用RTTI
//初始化的时候注册

DELPHI中使用RTTI
RegisterClasses([TApplication,TButton,TEdit,TMemo,TForm]);

DELPHI中使用RTTI


DELPHI中使用RTTI
end.

DELPHI中使用RTTI


DELPHI中使用RTTI


   注:示例程序在winxp+D7以及turbo delphi+winxp下测试通过。Borland文档中不包含将来也许会有版本变化的功能。当使用如RTTI等无文档说明的功能时,就不能保证你的程序可以完全移植到Delphi的未来版本。转载请注明出处!

  程序效果图如下:

DELPHI中使用RTTI


   编译、运行程序,你可以通过点击左上角列表框中的类型,获得他们的信息。而在窗体的下部,主要演示了通过读取配置信息来对控件的属性赋值(例程中的配置信息是通过edit输入的,可以在实际运用中改成从配置文件读取)。当使用下半部分功能时,在默认情况下,点击初始化按钮,然后点击修改,你会发现label1的caption变成了12345,并在在鼠标点击的时候会弹出一个对话框,你可以尝试把第一个edit的内容改成bitbtn1试试。
 
 
 
运行期类型信息(RTTI)是一种语言特征,能使应用程序在运行时得到关于对象的信息。RTTI是Delphi的组件能够融合到IDE中的关键。它在IDE中不仅仅是一个纯学术的过程。 由于对象都是从TObject继承下来的,因此,对象都包含一个指向它们的RTTI的指针以及几个内建的方法。下面的表列出了TObject的一些方法,用这些方法能获得某个对象实例的信息。 函数 返回类型 返回值 ClassName( ) string 对象的类名 ClassType() boolean 对象的类型 InheritsFrom boolean 判断对象是否继承于一个指定的类 ClassParent() TClass 对象的祖先类型 Instancesize() word 对象实例的长度(字节数) ClassInfo() Pointer 指向RTTI的指针 第一部分:关于as 和 is Object Pascal提供了两个运算符as和is,用它们通过RTTI能对对象进行比较和强制类型转换。 关键字as是类型转换的一种新的形式。它能把一个基层的对象强制类型转换成它的派生类,如果转换不合法就产生一个异常。假定有一个过程,想让它能够传递任何类型的对象,它应该这样定义: Procedure Foo(AnObject :Tobject); 在这个过程如果要对AnObject进行操作,要把它转换为一个派生对象。假定把AnObject看成是一个TEdit派生类型,并想要改变它所包含的文本,用下列代码: (AnObject as Tedit).text := 'wudi_1982'; 能用比较运算符来判断两个对象是否是相兼容的类型,用is运算符把一个未知的对象和一个已知类型或实例进行比较,确定这个未知对象的属性和行为。例如,在对(AnObject 进行强制类型转换前,确定(AnObject 和TEdit是否指针兼容: if (AnObject is Tedit) then Tedit(AnObjject).text := 'wudi_1982'; 注意在这个例子中不要再使用as进行强制类型转换,这是因为它要大量使用RTTI,另外还因为,在第一行已经判断Foo就是TEdit,可以通过在第2行进行指针转换来优化。 这两个操作符最典型的应用我想应该是在程序需要的部分清空窗体上所有edit的text属性 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.ClearEdit(Acontrl: TWinControl); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]i : integer; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] for i := 0 to Acontrl.ControlCount-1 do [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] if Acontrl.Controls[i] is TEdit then [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ((Acontrl.Controls[i]) as TEdit).Text := ''; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] if Acontrl.Controls[i] is TCustomControl then [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ClearEdit( (Acontrl.Controls[i] as TCustomControl)) [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; 第二部分:RTTI 上文中已经多次提到了RTTI,但好像并没有看到RTTI出现。那么RTTI是如何表现自己的呢?你将发现, RTTI至少在两个地方对你有用。第一个地方是DELPHI的IDE,这在前面已提到过。通过RTTI,IDE就会知道你正在使用的对象和组件的任何事情。实际上,不只是RTTI,但为了这个讨论,我们只谈RTTI方面。其实上面的as,is操作都间接的使用了RTTI。 还是用个例子来演示吧。在观看此例子之时,建议你看看typinfo.pas中的内容(DELPHI安装目录下\source\rtl\common\TypInfo.pas); 下面的例子主要分为两部分,界面上半部分,主要演示通过rtti来显示用户选择类型的信息。(有3个TListBox)。 下面的部分主要通过RTTI来完成通过配置信息对控件进行属性的赋值操作,这里将演示文本类型和事件类型的赋值。 窗体文件如下:代码如下: [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]object Form1: TForm1 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 150 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 161 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 639 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 372 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Caption = 'Form1' [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Color = clBtnFace [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Font.Charset = DEFAULT_CHARSET [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Font.Color = clWindowText [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Font.Height = -11 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Font.Name = 'Tahoma' [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Font.Style = [] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] OldCreateOrder = False [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] OnCreate = FormCreate [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] PixelsPerInch = 96 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TextHeight = 13 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object Panel1: TPanel [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 0 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 0 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 631 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 185 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Align = alTop [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 0 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object GroupBox1: TGroupBox [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 1 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 1 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 185 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 183 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Align = alLeft [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Caption = '在这里选择要查看类型的信息' [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 0 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object ListBox1: TListBox [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 2 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 15 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 181 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 166 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Align = alClient [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ItemHeight = 13 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 0 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] OnClick = ListBox1Click [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object GroupBox2: TGroupBox [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 368 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 1 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 262 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 183 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Align = alRight [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Caption = '属性信息' [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 1 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object ListBox3: TListBox [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 2 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 15 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 258 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 166 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Align = alClient [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ItemHeight = 13 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 0 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object GroupBox3: TGroupBox [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 186 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 1 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 182 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 183 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Align = alClient [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Caption = '基本信息' [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 2 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object ListBox2: TListBox [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 2 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 15 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 178 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 166 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Align = alClient [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ItemHeight = 13 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 0 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object TPanel [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 0 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 185 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 631 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 157 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Align = alClient [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 1 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object Panel2: TPanel [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 1 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 1 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 230 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 155 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Align = alLeft [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 0 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object Label2: TLabel [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 10 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 8 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 84 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 13 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Caption = '要修改的控件名' [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object Label3: TLabel [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 8 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 32 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 72 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 13 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Caption = '修改的属性名' [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object Label4: TLabel [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 8 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 64 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 72 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 13 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Caption = '将属性修改为' [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object edComName: TEdit [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 104 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 5 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 78 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 21 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 0 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Text = 'label1' [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object edPproName: TEdit [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 104 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 32 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 81 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 21 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 1 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Text = 'caption' [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object edValue: TEdit [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 104 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 56 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 81 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 21 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 2 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Text = '12345' [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object btnInit: TButton [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 8 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 104 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 75 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 25 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Caption = '初始化' [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 3 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] OnClick = btnInitClick [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object btnModify: TButton [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 104 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 104 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 75 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 25 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Caption = '修改' [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 4 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] OnClick = btnModifyClick [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object Panel3: TPanel [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 231 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 1 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 399 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 155 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Align = alClient [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 1 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object GroupBox4: TGroupBox [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 1 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 1 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 397 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 153 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Align = alClient [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Caption = '被修改的控件' [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 0 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object Label1: TLabel [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 16 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 32 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 28 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 13 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Caption = 'label1' [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] object BitBtn1: TBitBtn [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Left = 8 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Top = 64 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Width = 75 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Height = 25 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Caption = 'BitBtn1' [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TabOrder = 0 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{ [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/url] 作者:wudi_1982 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/url] 联系方式:wudi_1982@hotmail.com [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif[/img][/url] 转载请注明出处 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif[/img][/url]} [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]unit main; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]interface [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]uses [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]Forms, [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Dialogs,typinfo, StdCtrls, ExtCtrls, Buttons; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]type [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] InsertCom = record [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Name : string; //要修改属性的组件名 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] PproName : string;//要修改控件的属性名 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] MethodName :string;//要修改or添加给控件的事件名 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] text : string; //属性值,这里修改的是string类型的数值 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TForm1 = class(TForm) [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Panel1: TPanel; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] GroupBox1: TGroupBox; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ListBox1: TListBox; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] GroupBox2: TGroupBox; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] GroupBox3: TGroupBox; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ListBox2: TListBox; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ListBox3: TListBox; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Panel2: TPanel; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] edComName: TEdit; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Label2: TLabel; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Label3: TLabel; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] edPproName: TEdit; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Label4: TLabel; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] edValue: TEdit; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Panel3: TPanel; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] btnInit: TButton; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] btnModify: TButton; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] GroupBox4: TGroupBox; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Label1: TLabel; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] BitBtn1: TBitBtn; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure FormCreate(Sender: TObject); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure ListBox1Click(Sender: TObject); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure btnInitClick(Sender: TObject); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure btnModifyClick(Sender: TObject); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] private [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TestCom : InsertCom; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure MyClick(Sender : TObject); //给控件添加onclick事件 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] public [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url] ...{ Public declarations } [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Form1: TForm1; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]implementation [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$R *.dfm} [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]function CreateClass(const AClassName : string):TObject;//根据名字生成 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] tm : TObject; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] t : TFormClass; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] t := TFormClass(FindClass(AClassName)); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] tm := t.Create(nil); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Result := tm; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure GetBaseClassInfo(AClass : TObject;AStrings : TStrings); //获 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]得类型的基本信息 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] classTypeInfo : PTypeInfo; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ClassDataInfo : PTypeData; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] classTypeInfo := AClass.ClassInfo; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ClassDataInfo := GetTypeData(classTypeInfo); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] with AStrings do [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Add(Format('name is :%s',[classTypeInfo.Name])); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Add(format('type kind is :%s',[GetEnumName(TypeInfo [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url](TTypeKind),integer(classTypeInfo.Kind))])); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Add(Format('in : %s',[ClassDataInfo.UnitName])); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure GetBaseClassPro(AClass : TObject;Astrings : TStrings); //获 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]得属性信息 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] NumPro : integer; //用来记录事件属性的个数 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Pplst : PPropList; //存放属性列表 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Classtypeinfo : PTypeInfo; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] classDataInfo: PTypeData; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] i : integer; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Classtypeinfo := AClass.ClassInfo; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] classDataInfo := GetTypeData(Classtypeinfo); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] if classDataInfo.PropCount <> 0 then [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //分配空间 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] GetMem(Pplst,sizeof(PpropInfo)*classDataInfo.PropCount); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] try [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //获得属性信息到pplst [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] GetPropInfos(AClass.ClassInfo,Pplst); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] for I := 0 to classDataInfo.PropCount - 1 do [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] if Pplst[i]^.PropType^.Kind <> tkMethod then [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //这里过滤掉了事件属性 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Astrings.Add(Format('%s:%s',[Pplst[i]^.Name,Pplst[i] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]^.PropType^.Name])); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //获得事件属性 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] NumPro := GetPropList(AClass.ClassInfo,[tkMethod],Pplst); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] if NumPro <> 0 then [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //给列表添加一些标志 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Astrings.Add(''); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Astrings.Add('-----------EVENT-----------'); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Astrings.Add(''); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] for i := 0 to NumPro - 1 do //获得事件属性的列表 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Astrings.Add(Format('%s:%s',[Pplst[i]^.Name,Pplst[i] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]^.PropType^.Name])); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] finally [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FreeMem(Pplst,sizeof(PpropInfo)*classDataInfo.PropCount); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.btnInitClick(Sender: TObject); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //修改label1的caption属性为12345 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TestCom.Name := edComName.Text; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TestCom.PproName := edPproName.Text; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TestCom.text := edValue.Text; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TestCom.MethodName := 'OnClick'; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] btnModify.Enabled := true; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.btnModifyClick(Sender: TObject); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] pp : PPropInfo; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] obj : TComponent; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] a : TMethod; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] tm : TNotifyEvent; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] obj := FindComponent(TestCom.Name);//通过名字查找此控件 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] if not Assigned(obj) then exit; //如果没有则退出 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //通过getPropInfo获得指定控件的属性信息,注意,这里只能获得那些公开 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]了的属性 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] pp := GetPropInfo(obj.ClassInfo,TestCom.PproName); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] if Assigned(pp) then [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //根据kind判断类型是否为string类型 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] case pp^.PropType^.Kind of [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //这里使用setStrProp来为string类型的属性赋值,对起来类型的赋值 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url],请参考TypInfo.pas [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] tkString,tkLString,tkWString : SetStrProp [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url](obj,TestCom.PproName,TestCom.text); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //给要修改的控件添加onClick事件, [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] pp := GetPropInfo(obj.ClassInfo,TestCom.MethodName); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] if Assigned(pp) then [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] if pp^.PropType^.Kind = tkMethod then [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] tm := MyClick; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //Tmethod的code为函数地址,你也可以通过MethodAddress方法获得 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] a.Code := @tm; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] a.Data := Self; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //对时间赋值 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] SetMethodProp(obj,TestCom.MethodName,a); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.FormCreate(Sender: TObject); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] btnModify.Enabled := false; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //给listbox1添加一些类型的类名 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] with ListBox1.Items do [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Add('TApplication'); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Add('TEdit'); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Add('TButton'); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Add('Tmemo'); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Add('TForm'); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.ListBox1Click(Sender: TObject); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] t : TObject; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //当在类型列表中选择一个类型并用鼠标单击后,分别得到它的属性信息和 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]基本信息 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ListBox2.Clear; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ListBox3.Clear; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] t := CreateClass(ListBox1.Items[ListBox1.ItemIndex]); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] try [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] GetBaseClassInfo(t,ListBox2.Items); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] GetBaseClassPro(t,ListBox3.Items); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] finally [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] t.Free; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.MyClick(Sender: TObject); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //给指定控件添加的一个方法 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ShowMessage('wudi_1982'); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]initialization [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] //初始化的时候注册 [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] RegisterClasses([TApplication,TButton,TEdit,TMemo,TForm]); [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end. [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=/bbs/detail_501492.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] 注:示例程序在winxp+D7以及turbo delphi+winxp下测试通过。Borland文档中不包含将来也许会有版本变化的功能。当使用如RTTI等无文档说明的功能时,就不能保证你的程序可以完全移植到Delphi的未来版本。转载请注明出处! 程序效果图如下: [url=/bbs/detail_501492.html][img]http://p.blog.csdn.net/images/p_blog_csdn_net/wudi_1982/rtti使用演示界面.JPG[/img][/url] 编译、运行程序,你可以通过点击左上角列表框中的类型,获得他们的信息。而在窗体的下部,主要演示了通过读取配置信息来对控件的属性赋值(例程中的配置信息是通过edit输入的,可以在实际运用中改成从配置文件读取)。当使用下半部分功能时,在默认情况下,点击初始化按钮,然后点击修改,你会发现label1的caption变成了12345,并在在鼠标点击的时候会弹出一个对话框,你可以尝试把第一个edit的内容改成bitbtn1试试。
󰈣󰈤
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

 
 
>>返回首頁<<
 
 
 
 
 熱帖排行
 
 
王朝网络微信公众号
微信扫码关注本站公众号 wangchaonetcn
 
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味著赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有