核心提示:functionFindProperty(AClass:TObject;sPropertyName:String):Boolean; var PropList:PPropList; ClassType...
function FindProperty(AClass: TObject; sPropertyName: String): Boolean; var
PropList: PPropList;
ClassTypeInfo: PTypeInfo;
ClassTypeData: PTypeData;
i: integer;
begin
Result := False;
ClassTypeInfo := aClass.ClassType.ClassInfo;
ClassTypeData := GetTypeData(ClassTypeInfo);
if ClassTypeData.PropCount <> 0 then
begin
GetMem(PropList, SizeOf(PPropInfo) * ClassTypeData.PropCount);
try
GetPropInfos(AClass.ClassInfo, PropList);
for i := 0 to ClassTypeData.PropCount - 1 do
if (PropList[i]^.PropType^.Kind <> tkMethod)
and (UpperCase(PropList[i]^.Name) = UpperCase(sPropertyName)) then
begin
Result := True;
Break;
end;
finally
FreeMem(PropList, SizeOf(PPropInfo) * ClassTypeData.PropCount);
end;
end;
end;