我从我的组态软件中摘录了一段,不懂再联系aiirii@21cn.com
procedure TfrmProperty.GetClassProperties(AClass: TObject; AStringsName,AStringsType: TStrings);
{ This method retrieves the property names and types for the given object
and adds that information to the AStrings parameter. }
var
PropList: PPropList;
ClassTypeInfo: PTypeInfo;
ClassTypeData: PTypeData;
i: integer;
// NumProps: Integer;
begin
ClassTypeInfo := AClass.ClassInfo;
ClassTypeData := GetTypeData(ClassTypeInfo);
if ClassTypeData.PropCount <> 0 then
begin
// allocate the memory needed to hold the references to the TPropInfo
// structures on the number of properties.
GetMem(PropList, SizeOf(PPropInfo) * ClassTypeData.PropCount);
try
// fill PropList with the pointer references to the TPropInfo structures
GetPropInfos(AClass.ClassInfo, PropList);
for i := 0 to ClassTypeData.PropCount - 1 do
// filter out properties that are events ( method pointer properties)
if not (PropList^.PropType^.Kind = tkMethod) then
begin
AStringsName.Add(PropList^.Name);
AStringsType.Add(PropList^.PropType^.Name);
end; // AStrings.Add(Format('%s: %s', [PropList^.Name, PropList^.PropType^.Name]));
finally
FreeMem(PropList, SizeOf(PPropInfo) * ClassTypeData.PropCount);
end;
end;
end;