这段代码可以显示一个对象的属性
Procedure GetProperties(tobject : TObject);
var
PropList : PPropList;
i : Integer;
begin
PropList := AllocMem(SizeOf(PropList^));
i := 0;
try
GetPropList(PTypeInfo (tobject.ClassInfo), [tkMethod], PropList);
while (PropList^[i] <> Nil) and (i < High(PropList^)) do
begin
MessageDlg(PropList^[i].Name + ': ' + PropList^[i].PropType^.Name,
mtInformation, [mbOK], 0);
Inc(i);
end;
finally
FreeMem(PropList);
end;
end;
在使用中发现,它只能显示TComponent类或者由TComponent派生的类 的对象 的所有属性,其他的非TComponent派生的类 的对象,是什么都得不到。请问 : 我该怎么得到一个类的所有可以访问的属性(包括隐含属性)。分不够再加。GetPropList,GetPropInfo..那几个函数/过程 我都试过了不行,如果是这方面作回答的朋友,请先试一下然后才回复,因为我觉得用这几个函数不可能得到,所以
Procedure GetProperties(tobject : TObject);
var
PropList : PPropList;
i : Integer;
begin
PropList := AllocMem(SizeOf(PropList^));
i := 0;
try
GetPropList(PTypeInfo (tobject.ClassInfo), [tkMethod], PropList);
while (PropList^[i] <> Nil) and (i < High(PropList^)) do
begin
MessageDlg(PropList^[i].Name + ': ' + PropList^[i].PropType^.Name,
mtInformation, [mbOK], 0);
Inc(i);
end;
finally
FreeMem(PropList);
end;
end;
在使用中发现,它只能显示TComponent类或者由TComponent派生的类 的对象 的所有属性,其他的非TComponent派生的类 的对象,是什么都得不到。请问 : 我该怎么得到一个类的所有可以访问的属性(包括隐含属性)。分不够再加。GetPropList,GetPropInfo..那几个函数/过程 我都试过了不行,如果是这方面作回答的朋友,请先试一下然后才回复,因为我觉得用这几个函数不可能得到,所以
没有RTTI信息
另,RTTI指Published域的信息,没有所谓隐含的属性.
-------------
Returns a pointer to the runtime type information (RTTI) table for the object type.Delphi syntax:class function ClassInfo: Pointer;C++ syntax:static void * __fastcall ClassInfo(TClass cls);
void * __fastcall ClassInfo(){return ClassInfo(ClassType()); }DescriptionClassInfo provides access to the RTTI table for a given object type.Note: The format of the RTTI table is subject to change. Applications should use the other RTTI methods provided by TObject; these provide easy, consistent access to RTTI data.
Note: Some classes do not provide runtime type information. For these classes, ClassInfo returns nil (Delphi) or NULL (C++). All classes descended from TPersistent do provide runtime type information.