Jump to content
Sign in to follow this  
Attila Kovacs

Inherited on Properties and co.

Recommended Posts

Since when does inherited work on properties?  "Inherited Data". And where else except the obvious? Documentation?

I was annoyed that I could not set FData as it is private so I gave him an "inherited" in anger and fury and the compiler wasn't complaining. 😮

 

  TTreeNodeHelper = class helper for TTreeNode
  private
    function GetNodeData: TNodeData;
    procedure SetNodeData(const Value: TNodeData);
  public
    property Data: TNodeData read GetNodeData write SetNodeData;
  end;

function TVariantenTreeNodeHelper.GetNodeData: TNodeData;
begin
  Result := inherited Data;
end;

procedure TVariantenTreeNodeHelper.SetNodeData(const Value: TNodeData);
begin
  inherited Data := Value;
end;

 

Edited by Attila Kovacs

Share this post


Link to post
48 minutes ago, Attila Kovacs said:

Since when does inherited work on properties? 

At least since Delphi 7 (cannot check versions below in the moment). Just have a look at DB.pas (out of many others):

function TFieldDefs.GetFieldDef(Index: Integer): TFieldDef;
begin
  Result := TFieldDef(inherited Items[Index]);
end;

or the ancient Contnrs.pas:

function TObjectList.GetItem(Index: Integer): TObject;
begin
  Result := inherited Items[Index];
end;

 

  • Like 1

Share this post


Link to post
31 minutes ago, Alexander Elagin said:

From the very beginning, i.e Delphi 1.

Thx.

 

31 minutes ago, Alexander Elagin said:

What's the problem?

The gas prices. 😉

  • Haha 1

Share this post


Link to post
14 hours ago, Alexander Elagin said:

From the very beginning, i.e Delphi 1. What's the problem?

I guess private is not private - unless strict private?

Share this post


Link to post
3 minutes ago, Lars Fosdal said:

I guess private is not private - unless strict private?

FData is private, but the helper sets inherited Data, which is public.

  • Like 2

Share this post


Link to post

If it is public, why do you need to use inherited?

I think the point just wooshed over my head here.

(Not the first time)

Share this post


Link to post

 

20 minutes ago, Lars Fosdal said:

If it is public, why do you need to use inherited?

Because Data property is re-introduced with a new signature, thus it is necessary to explicitly use the inherited property and not the new one.

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
Sign in to follow this  

×