| 導購 | 订阅 | 在线投稿
分享
 
 
當前位置: 王朝網路 >> delphi >> DELPHI中使用RTTI
 

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試試。
 
 
 
上一篇《Borland傳奇拾遺:Delphi 8》
下一篇《DELPHI中的記錄類型【存儲方式和變體記錄】》
 
 
 
 
 
 
日版寵物情人插曲《Winding Road》歌詞

日版寵物情人2017的插曲,很帶節奏感,日語的,女生唱的。 最後聽見是在第8集的時候女主手割傷了,然後男主用嘴幫她吸了一下,插曲就出來了。 歌手:Def...

兄弟共妻,我成了他們夜裏的美食

老鍾家的兩個兒子很特別,就是跟其他的人不太一樣,魔一般的執著。兄弟倆都到了要結婚的年齡了,不管自家老爹怎麽磨破嘴皮子,兄弟倆說不娶就不娶,老父母爲兄弟兩操碎了心...

如何磨出破洞牛仔褲?牛仔褲怎麽剪破洞?

把牛仔褲磨出有線的破洞 1、具體工具就是磨腳石,下面墊一個硬物,然後用磨腳石一直磨一直磨,到把那塊磨薄了,用手撕開就好了。出來的洞啊很自然的。需要貓須的話調幾...

我就是掃描下圖得到了敬業福和愛國福

先來看下敬業福和愛國福 今年春節,支付寶再次推出了“五福紅包”活動,表示要“把欠大家的敬業福都還給大家”。 今天該活動正式啓動,和去年一樣,需要收集“五福”...

冰箱異味産生的原因和臭味去除的方法

有時候我們打開冰箱就會聞到一股異味,冰箱裏的這種異味是因爲一些物質發出的氣味的混合體,聞起來讓人惡心。 産生這些異味的主要原因有以下幾點。 1、很多人有這種習...

《極品家丁》1-31集大結局分集劇情介紹

簡介 《極品家丁》講述了現代白領林晚榮無意回到古代金陵,並追隨蕭二小姐化名“林三”進入蕭府,不料卻陰差陽錯上演了一出低級家丁拼搏上位的“林三升職記”。...

李溪芮《極品家丁》片尾曲《你就是我最愛的寶寶》歌詞

你就是我最愛的寶寶 - 李溪芮 (電視劇《極品家丁》片尾曲) 作詞:常馨內 作曲:常馨內 你的眉 又鬼馬的挑 你的嘴 又壞壞的笑 上一秒吵鬧 下...

烏梅的功效與作用以及烏梅的食用禁忌有哪些?

烏梅,又稱春梅,中醫認爲,烏梅味酸,性溫,無毒,具有安心、除熱、下氣、祛痰、止渴調中、殺蟲的功效,治肢體痛、肺痨病。烏梅泡水喝能治傷寒煩熱、止吐瀉,與幹姜一起制...

什麽是脂肪粒?如何消除臉部脂肪粒?

什麽是脂肪粒 在我們的臉上總會長一個個像脂肪的小顆粒,弄也弄不掉,而且顔色還是白白的。它既不是粉刺也不是其他的任何痘痘,它就是脂肪粒。 脂肪粒雖然也是由油脂...

網絡安全治理:國家安全保障的主要方向是打擊犯罪,而不是處置和懲罰受害者

來源:中國青年報 新的攻擊方法不斷湧現,黑客幾乎永遠占據網絡攻擊的上風,我們不可能通過技術手段杜絕網絡攻擊。國家安全保障的主要方向是打擊犯罪,而不是處置和懲罰...

河南夫妻在溫嶺網絡直播“造人”內容涉黃被刑事拘留

夫妻網絡直播“造人”爆紅   1月9日,溫嶺城北派出所接到南京警方的協查通告,他們近期打掉了一個涉黃直播APP平台。而根據掌握的線索,其中有一對涉案的夫妻主播...

如何防止牆紙老化?牆紙變舊變黃怎麽辦?

如何防止牆紙老化? (1)選擇透氣性好的牆紙 市場上牆紙的材質分無紡布的、木纖維的、PVC的、玻璃纖維基材的、布面的等,相對而言,PVC材質的牆紙最不透氣...

鮮肌之謎非日本生産VS鮮肌之謎假日貨是謠言

觀點一:破日本銷售量的“鮮肌之謎” 非日本生産 近一段時間,淘寶上架了一款名爲“鮮肌之謎的” 鲑魚卵巢美容液,號稱是最近日本的一款推出的全新護膚品,産品本身所...

中國最美古詩詞精選摘抄

系腰裙(北宋詞人 張先) 惜霜蟾照夜雲天,朦胧影、畫勾闌。人情縱似長情月,算一年年。又能得、幾番圓。 欲寄西江題葉字,流不到、五亭前。東池始有荷新綠,尚小如...

關于女人的經典語句

關于女人的經典語句1、【做一個獨立的女人】 思想獨立:有主見、有自己的人生觀、價值觀。有上進心,永遠不放棄自己的理想,做一份自己喜愛的事業,擁有快樂和成就...

未來我們可以和性愛機器人結婚嗎?

你想體驗機器人性愛嗎?你想和性愛機器人結婚嗎?如果你想,機器人有拒絕你的權利嗎? 近日,第二屆“國際人類-機器人性愛研討會”大會在倫敦金史密斯大學落下帷幕。而...

全球最變態的十個地方

10.土耳其地下洞穴城市 變態指數:★★☆☆☆ 這是土耳其卡帕多西亞的一個著名景點,傳說是當年基督教徒們爲了躲避戰爭而在此修建。裏面曾住著20000人,...

科學家稱,人類死亡後意識將在另外一個宇宙中繼續存活

據英國《每日快報》報道,一位科學家兼理論家Robert Lanza博士宣稱,世界上並不存在人類死亡,死亡的只是身體。他認爲我們的意識借助我們體內的能量生存,而且...

《屏裏狐》片頭曲《我愛狐狸精》歌詞是什麽?

《我愛狐狸精》 - 劉馨棋   (電視劇《屏裏狐》主題曲)   作詞:金十三&李旦   作曲:劉嘉   狐狸精 狐狸仙   千年修...

 
 
 
運行期類型信息(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試試。
󰈣󰈤
 
 
 
  免責聲明:本文僅代表作者個人觀點,與王朝網路無關。王朝網路登載此文出於傳遞更多信息之目的,並不意味著贊同其觀點或證實其描述,其原創性以及文中陳述文字和內容未經本站證實,對本文以及其中全部或者部分內容、文字的真實性、完整性、及時性本站不作任何保證或承諾,請讀者僅作參考,並請自行核實相關內容。
 
 
小龍女彤彤之情溢皇都
龔潔
智能手機形象美女
崔潔彤
回家的路上----
中國一站(哈爾濱)
清明植物園的花。
桃花堤印象之豎版
 
>>返回首頁<<
 
 熱帖排行
 
 
 
 
© 2005- 王朝網路 版權所有