unit Un_Main;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,TypInfo,QActnList,QStdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
lbClasses: TListBox;
btnGetClasses: TButton;
Label2: TLabel;
lbClassInfo: TListBox;
Label3: TLabel;
lbProperty: TListBox;
procedure lbClassesClick(Sender: TObject);
procedure btnGetClassesClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function CreateClass(const AClassName:string):TObject;
procedure GetClassInfo(AClass:TObject;AStrings:TStrings);
procedure GetClassAncestor(AClass:TObject;AStrings:TStrings);
procedure GetClassProperty(AClass:TObject;AStrings:TStrings);
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.lbClassesClick(Sender: TObject);
begin
with lbClasses.Items do begin
clear;
Add('TApplication');
Add('TForm');
Add('TButton');
Add('TComponent');
Add('TGraphicControl');
Add('TListBox');
Add('TComboBox');
Add('TLabel');
Add('TActionList');
end;
RegisterClasses([TApplication,TForm,TButton,TComponent,TgraphicControl,
TlistBox,TComboBox,TLabel,TActionList]);
end;function TForm1.CreateClass(const AClassName:String):TObject;
var
C:TFormClass;
Obj:TObject;
begin
C:=TFormClass(FindClass(AClassName));
Obj:=C.Create(nil);
Result:=Obj;
end;procedure TForm1.GetClassAncestor(AClass:TObject;AStrings:TStrings);
var
AC:TClass;
begin
AC:=AClass.ClassParent;
AStrings.Add('Class Ancestry');
while AC<>nil do
begin
AStrings.Add(Format(' %s',[AC.ClassName]));
AC:=AC.ClassParent;
end;
end;procedure TForm1.GetClassInfo(AClass:TObject;AStrings:TStrings);
var
TI:PTypeInfo;
TD:PTypeData;
EnumName:String;
begin
TI:=AClass.ClassInfo;
TD:=GetTypeData(TI);
with AStrings do
begin
Add(Format('Class Name: %s',[TI.Name]));
EnumName:=GetEnumname(TypeInfo(TTypeKind),Integer(TI.Kind));
Add(Format('Kind: %s',[EnumName]));
Add(Format('Size: %d',[AClass.InstanceSize]));
Add(Format('Defined in: %s.pas',[TD.Unitname]));
Add(Format('Num Propetties: %d',[TD.PropCount]));
end;
end;procedure TForm1.GetClassProperty(AClass:TObject;AStrings:TStrings);
var
PropList:PPropList;
TI:PTypeInfo;
TD:PTypeData;
i:integer;
NumProps:integer;
begin
TI:=AClass.ClassInfo;
TD:=GetTypeData(TI); if TD.PropCount<>0 then
begin
GetMem(PropList,SizeOf(PPropInfo)*TD.PropCount);
try
GetPropInfos(AClass.ClassInfo,PropList);
for i:=0 to TD.PropCount-1 do
if not(PropList[i]^.PropType^.Kind=tkMethod)then
AStrings.Add(Format('%s:%s',[PropList[i]^.Name,
PropList[i]^.PropType^.Name]));
NumProps:=GetPropList(AClass.ClassInfo,[tkMethod],PropList);
if NumProps<>0 then
begin
AStrings.Add('');
AStrings.Add('------Events------');
AStrings.Add('');
end;
for i:=0 to Numprops-1 do
AStrings.Add(Format('%s:%s',[PropList[i]^.Name,
PropList[i]^.PropType^.Name])); finally
FreeMem(PropList,SizeOf(PPropInfo)*TD.PropCount);
end;
end;
end;
procedure TForm1.btnGetClassesClick(Sender: TObject);
var
Cls:TObject;
ClassName:string;
begin
lbClassInfo.Items.Clear;
lbProperty.Items.Clear; try
ClassName:=lbClasses.Items[lbClasses.ItemIndex];
Cls:=CreateClass(ClassName);
try
GetClassInfo(Cls,lbClassInfo.Items);
GetClassAncestor(Cls,lbClassInfo.Items);
GetClassProperty(Cls,lbProperty.Items);
finally
Cls.Free;
end;
except on E:EClassNotFound do
showMessage('Class not Fount');
end;
end;end.
这是源程式
请各位帮我分析一下这是怎么一回事
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,TypInfo,QActnList,QStdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
lbClasses: TListBox;
btnGetClasses: TButton;
Label2: TLabel;
lbClassInfo: TListBox;
Label3: TLabel;
lbProperty: TListBox;
procedure lbClassesClick(Sender: TObject);
procedure btnGetClassesClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function CreateClass(const AClassName:string):TObject;
procedure GetClassInfo(AClass:TObject;AStrings:TStrings);
procedure GetClassAncestor(AClass:TObject;AStrings:TStrings);
procedure GetClassProperty(AClass:TObject;AStrings:TStrings);
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.lbClassesClick(Sender: TObject);
begin
with lbClasses.Items do begin
clear;
Add('TApplication');
Add('TForm');
Add('TButton');
Add('TComponent');
Add('TGraphicControl');
Add('TListBox');
Add('TComboBox');
Add('TLabel');
Add('TActionList');
end;
RegisterClasses([TApplication,TForm,TButton,TComponent,TgraphicControl,
TlistBox,TComboBox,TLabel,TActionList]);
end;function TForm1.CreateClass(const AClassName:String):TObject;
var
C:TFormClass;
Obj:TObject;
begin
C:=TFormClass(FindClass(AClassName));
Obj:=C.Create(nil);
Result:=Obj;
end;procedure TForm1.GetClassAncestor(AClass:TObject;AStrings:TStrings);
var
AC:TClass;
begin
AC:=AClass.ClassParent;
AStrings.Add('Class Ancestry');
while AC<>nil do
begin
AStrings.Add(Format(' %s',[AC.ClassName]));
AC:=AC.ClassParent;
end;
end;procedure TForm1.GetClassInfo(AClass:TObject;AStrings:TStrings);
var
TI:PTypeInfo;
TD:PTypeData;
EnumName:String;
begin
TI:=AClass.ClassInfo;
TD:=GetTypeData(TI);
with AStrings do
begin
Add(Format('Class Name: %s',[TI.Name]));
EnumName:=GetEnumname(TypeInfo(TTypeKind),Integer(TI.Kind));
Add(Format('Kind: %s',[EnumName]));
Add(Format('Size: %d',[AClass.InstanceSize]));
Add(Format('Defined in: %s.pas',[TD.Unitname]));
Add(Format('Num Propetties: %d',[TD.PropCount]));
end;
end;procedure TForm1.GetClassProperty(AClass:TObject;AStrings:TStrings);
var
PropList:PPropList;
TI:PTypeInfo;
TD:PTypeData;
i:integer;
NumProps:integer;
begin
TI:=AClass.ClassInfo;
TD:=GetTypeData(TI); if TD.PropCount<>0 then
begin
GetMem(PropList,SizeOf(PPropInfo)*TD.PropCount);
try
GetPropInfos(AClass.ClassInfo,PropList);
for i:=0 to TD.PropCount-1 do
if not(PropList[i]^.PropType^.Kind=tkMethod)then
AStrings.Add(Format('%s:%s',[PropList[i]^.Name,
PropList[i]^.PropType^.Name]));
NumProps:=GetPropList(AClass.ClassInfo,[tkMethod],PropList);
if NumProps<>0 then
begin
AStrings.Add('');
AStrings.Add('------Events------');
AStrings.Add('');
end;
for i:=0 to Numprops-1 do
AStrings.Add(Format('%s:%s',[PropList[i]^.Name,
PropList[i]^.PropType^.Name])); finally
FreeMem(PropList,SizeOf(PPropInfo)*TD.PropCount);
end;
end;
end;
procedure TForm1.btnGetClassesClick(Sender: TObject);
var
Cls:TObject;
ClassName:string;
begin
lbClassInfo.Items.Clear;
lbProperty.Items.Clear; try
ClassName:=lbClasses.Items[lbClasses.ItemIndex];
Cls:=CreateClass(ClassName);
try
GetClassInfo(Cls,lbClassInfo.Items);
GetClassAncestor(Cls,lbClassInfo.Items);
GetClassProperty(Cls,lbProperty.Items);
finally
Cls.Free;
end;
except on E:EClassNotFound do
showMessage('Class not Fount');
end;
end;end.
这是源程式
请各位帮我分析一下这是怎么一回事
解决方案 »
- delphi 2010 简单小问题,请教
- ADO如何取得ECXEL表的全部列名称
- 请问如何访问类里面的一个结构中的成员?????????????????????
- 如何在QuickRep1中实现动态打印!就是说他关联的表字段是动态变化的!,那位高手给点代码看啊!
- 如何获得当前应用的完整路径,GetModuleFileName好象不行?!
- 几种开发语言的结合
- 如何在一个目录上,取到时间最新的一个?
- 简单的交互式聊天系统
- bcb 中像 “is” 一样的操作有吗?
- 一个简单的数组问题..
- 在turbo pascal下问题(怎么发出音乐)
- doa怎么用啊?就是直接连ORACLE的哪个,我下来一看全是。PAS文件,连个readme也没有
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,TypInfo,QActnList,QStdCtrls;去掉
QActnList,QStdCtrls 这两个单元,它们用于 CLX(交叉平台组件库)