[fpc-pascal] 2.1.1 new protected

Mattias Gaertner nc-gaertnma at netcologne.de
Fri Aug 11 15:08:44 CEST 2006


On Fri, 11 Aug 2006 14:49:16 +0200
"Graeme Geldenhuys" <graemeg.lists at gmail.com> wrote:

> On 8/11/06, Michael Van Canneyt <michael at freepascal.org> wrote:
> > It seems normal to me that it is not just the current instance.  You KNOW this
> > method is there, in a descendent, so it seems logical that you know that it
> > exists for another instance as well.
> 
> Coming from a Delphi background, I disagree here.  As I understood the
> Delphi docs, protected methods are only visible in the current
> instance (decendant), and not instances passed in as parameters.

It does not matter how you got the instance, via parameter, variable or function.
Only the class of the instance matters.

The screenshot says:
A protected member is visible [...] from any descendant class.
A protected method can be called from the definition of any method belonging to a class that descends from the one where the protected member is declared.

Where do you read here anything about 'current instance'?

IMO the old 'Protected' was very easy to explain to people:
"Is the same as Private, except that the members of a Protected section are also accessible to descendent types, even if they are implemented in other modules."
No exceptions. Pretty straight.

And it was very Delphi compatible. I mean, how many Delphians noticed the difference at all? It didn't hurt and gave more flexibility. So, I second Michael's proposal to at least keep it in mode objfpc.

 
> Reading the docs again, I am not sure what happens when both those
> classes appear in the same unit.  This then becomes like the "friend"
> classes used in C++ and C# and might be allowed in such a case...
> Quite confusing... :-)
> 
> Here is a snippet of the Kylix 3 docs:
> 
> ------------------------
> ... See attached image, I couldn't cut and paste from CLX....
> ------------------------


Mattias



More information about the fpc-pascal mailing list