[fpc-pascal] Published -> Public

Martin fpc at mfriebe.de
Sat Apr 17 02:24:05 CEST 2010


On 17/04/2010 00:29, Marc Weustink wrote:
> Flávio Etrusco wrote:
>> On Fri, Apr 16, 2010 at 4:54 PM, José Mejuto <joshyfun at gmail.com> wrote:
>>> Hello FPC-Pascal,
>>>
>>> Friday, April 16, 2010, 9:06:45 PM, you wrote:
>>>
>>> FE> Published methods can be found with TObject.MethodAddress, 
>>> that's how
>>> FE> the lfm hook event handlers (and why Form event handlers are
>>> FE> published).
>>>
>>> Yes, but thats for streamable objects like TForm, or any component,
>>> but I think that that's not the case of TWSxxxx objects which are the
>>> widgetset interface, and also all of them are "class procedure".
>>>
>>> Marc says in Lazarus that a "virtual class tree" is formed with such
>>> published methods, I do not know the need of it or the mission, but if
>>> it is OK it is OK ;) for me.
>>>
>>> -- 
>>> Best regards,
>>>  José
>>
>> Sure, I was just saying that in a different context. I found Marc's
>> observation very weird, and I'm (still) going to check it.
>
> Its not my observation, but my implementations :)
>
>
>
> Imagine the following "base" widgetdset tree (best viewed with a fixed 
> font)
>
> TWSBase
>  |
>  + TWSWinControl
>  |  |
>  |  + TWSButton
>  |
>  + TWSSomeOther
>
>
> Now we have a widgetset, say XXX, implementing these classes
>
> when you use the normal inheritence you get a tree like:
>
> TWSBase - TWSXXXBase
>  |
>  + TWSWinControl - TWSXXXWinControl
>  |  |
>  |  + TWSButton - TWSXXXButton
>  |
>  + TWSSomeOther - TWSXXXSomeOther
>
> Now you see a problem here. You would expect TWSXXXButton to be 
> derived from TWSXXXWinControl, but it isn't, so it doesn't have the 
> TWSXXXWinControl implementation.
>
> Now comes the "vitrual" class tree lazarus uses. Based on RTTI it 
> creates its own VMT tables, rewriting the tree to:
>
> TWSBase
>  |
>  + TWSXXXBase
>     |
>     + TWSWinControl
>     |  |
>     |  + TWSXXXWinControl
>     |     |
>     |     + TWSButton
>     |        |
>     |        + TWSXXXButton
>     |
>     + TWSSomeOther
>        |
>        + TWSXXXSomeOther
>
>
> Now TWSXXXButton is derived from TWSXXXWinControl

Interesting.....

I thought (not even sure why I thought it, or were I pcked it up; so it 
may be wrong, in which case just tell me)...
... that the compiler could optimize an "inherited" call.

TBase = class
   procedure Foo; virtual;
end

TChild= class
   procedure Foo; override;
end

Now if I call "BaseVariable.Foo" from anywhere, it needs to find Foo in 
the VMT, because the actual object could be of either class.

BUT

procedure TChild.Foo;
begin
   inherited;  // or:  inerithed Foo;
   // do more
end;

I thought that in this last case, the compiler would know, that 
inherited points to TBase.Foo; and the compiler would optimize the code, 
to call directly (skipping the VMT) ?

But I guess I am wrong about that? OR how else could the above work?

Martin



More information about the fpc-pascal mailing list