Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-11

use of "inherited" keyword

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Xiangrong Fang

Hi,

Is it OK to use "inherited" in any instance method? i.e.

It is OK to do this:

procedure TChildClass.DoIt;//override
begin
  inherited DoIt;
end;

But is it ok to do this:

procedure TChildClass.SomethinElse;//NOT DoIt
begin
  inherited DoIt;
  //... ...
end;

I tried, it seems ok, but I am not sure, because I had a strange access violation in my code which I cannot reproduce in simplified version of the code, so I suspect this might be an invalid use and "correct by coincidence"?

Thanks!
Xiangrong

Reply by email

Sven Barth
to Xiangrong Fang
Xiangrong Fang wrote 23 lines
Hi, Is it OK to use "inherited" in any instance method? i.e. It is OK to do this: procedure TChildClass.DoIt;//override begin inherited DoIt; end; But is it ok to do this: procedure TChildClass.SomethinElse;//NOT DoIt begin inherited DoIt; //... ... end; I tried, it seems ok, but I am not sure, because I had a strange access violation in my code which I cannot reproduce in simplified version of the code, so I suspect this might be an invalid use and "correct by coincidence"?

You can always use "inherited" to call a method of the given name in the next parent class that has such a method (Note: there are a few exceptions: If no such methods exist (compile time error) and if the method is abstract (also compile time error))

Regards,
Sven

Reply by email