![]() |
Wie feststellen ob Property geerbt ist?
Moin moin zusammen,
wie kann ich ermitteln, ob die Property eines TOBject-Nachfahren in diesem definiert wurde oder vom vorfahren geerbt ist? Ich weis das ich das mittels RTTI rausfinden kann, ich suche allerdings den Punkt wo ich diese Information beziehen kann... Hat jemand einen Hinweis für mich? Danke! |
Re: Wie feststellen ob Property geerbt ist?
Über RTTI bekommst du IMHO nur raus, wann das Property published wurde.
Dazu brauchst du Unit TypInfo und IsPublishedProp. |
Re: Wie feststellen ob Property geerbt ist?
Wie schon erwähnt, funktioniert das über RTTI nur mit published Properties.
Im folgenden Beispiel wird die Eigenschaft 'Value' in der Basisklasse TFoo nicht gefunden:
Delphi-Quellcode:
uses
TypInfo; type TFoo = class(TObject) private FValue: Integer; public property Value: Integer read FValue; end; type TBar = class(TFoo) published property Value; end; procedure FooBar(); const Name = 'Value'; var Info: PTypeInfo; Data: PTypeData; begin Info := TypeInfo(TBar); while Assigned(Info) do begin ShowMessage(GetEnumName(TypeInfo(TTypeKind), Integer(Info.Kind)) + #10 + Info.Name + #10 + '''' + Name + ''' found: ' + BoolToStr( (Info.Kind = tkClass) and Assigned(GetPropInfo(Info, Name)), True)); // Get parent info Data := GetTypeData(Info); if not Assigned(Data) then Info := nil else case Info.Kind of tkSet: if Assigned(Data.CompType) then Info := Data.CompType^ else Info := nil; tkClass: if Assigned(Data.ParentInfo) then Info := Data.ParentInfo^ else Info := nil; tkInterface: if Assigned(Data.IntfParent) then Info := Data.IntfParent^ else Info := nil; else Info := nil; end; end; end; |
Re: Wie feststellen ob Property geerbt ist?
Danke für die antworten, hat aber alles nix geholfen weil irgendwie an meiner Frage vorbei.
Hab's wie folgt gelöst:
Delphi-Quellcode:
if Item.ClassParent.InheritsFrom(TCustomOPFBOItem)
and IsPublishedProp(Item.ClassParent, PropList[i]^.Name) then DoSomthing; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:59 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz