Jump to content
havrlisan

Redeclaring property in a child class

Recommended Posts

Is it possible to know if a property is redeclared in a class or skip the original property entirely (the redeclared property would overwrite the original property in the Rtti)?

 

It's easier to explain through an example:

TMyClass = class
  strict private
    FInt: Integer;
  public
    property Int: Integer read FInt write FInt;
end;

TMyChild = class(TMyClass)
  published
    [RandomAttr]
    property Int;
end;

 

The Rtti will return 2 properties for TMyChild class, even though both have the same name. I haven't found any data in the TRttiProperty that would indicate that the property is redeclared.

 

Second question would be, if this is not possible: can I rely on the returned properties to be sorted by class inheritance? In other words, can I safely assume the returned array of properties would first contain properties of TMyChild, and then of TMyClass?

Share this post


Link to post
2 minutes ago, havrlisan said:

Second question would be, if this is not possible: can I rely on the returned properties to be sorted by class inheritance? In other words, can I safely assume the returned array of properties would first contain properties of TMyChild, and then of TMyClass?

Should've searched at least a bit before asking this question.. Digging into TRttiType.GetProperties I found the method TRttiTypeHelper.GetObjectListInVisOrder, which does exactly what I'm asking here.

 

Original question still stands, although knowing this is enough to handle my scenario.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×