[fpc-pascal]inherited keyword

Thomas Schatzl tom_at_work at gmx.at
Sun Dec 21 18:02:43 CET 2003


Hello,


> > Can someone explain the semantic difference between *1 and *2 please?
> >
> > procedure A(p: Type1);
> > begin
> >   inherited; // *1
> >   inherited A(p); // *2
> > end;
> >
> > ?
>
> 1: supporting a delphi bug
> 2: as you expect
>
> Well, the comment to 1 isn't completly true: In method handlers
> (declared with message XXX), a simply inherited should pass the message
> to the parent message handle while in usual methods it does nothing.

According to the D7 docs both types of syntaxes (sp?) are completely legal
and defined such that both terms are semantically equal.

---- snip from D7 docs:

The reserved word inherited plays a special role in implementing polymorphic
behavior. It can occur in method definitions, with or without an identifier
after it.

If inherited is followed by the name of a member, it represents a normal
method call or reference to a property or field--except that the search for
the referenced member begins with the immediate ancestor of the enclosing
method's class. [Type 2]

[...example omitted...]

When inherited has no identifier after it, it refers to the inherited method
with the same name as the enclosing method or, if the enclosing method is a
message handler, to the inherited message handler for the same message. In
this case, inherited takes no explicit parameters, but passes to the
inherited method the same parameters with which the enclosing method was
called. [Type 1]

[...example omitted...]

--- snip end

Or am I misinterpreting these few lines?

Probably they [the Borland guys] adapted the docs for buggy behaviour of
earlier Delphi versions... =)

Regards,
  Thomas





More information about the fpc-pascal mailing list