Sign in Join

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

Mailing lists / fpc-pascal / 2010-04

Published -> Public

15 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

José Mejuto

Hello FPC-Pascal,

If I have a class like:

TMyClassPublished=class(TObject)
published
  procedure MyProcedure; virtual;
end;

And a derived one:

TMyClassDerived=class(TMyClassPublished)
public
  procedure MyProcedure; override;
end;

Is there any difference in the derived one with less visibility in the method ? This means, does it use less/more memory, more/less calling speed, more/less RTTI information, ... ?

Thank you.

Best regards, José

Reply by email

Marc Weustink
to José Mejuto
José Mejuto wrote 19 lines
Hello FPC-Pascal, If I have a class like: TMyClassPublished=class(TObject) published procedure MyProcedure; virtual; end; And a derived one: TMyClassDerived=class(TMyClassPublished) public procedure MyProcedure; override; end; Is there any difference in the derived one with less visibility in the method ? This means, does it use less/more memory, more/less calling speed, more/less RTTI information, ... ?

no, no, no, no

You cannot lower visibility, since the following example is still possible:

var
   a:TMyClassPublished;
begin
   a := TMyClassDerived.Create;
   a.MyProcedure;
end;

it will use the scope of a and not the "redefined" scope in TMyClassDerived

Marc

Reply by email

José Mejuto
to Marc Weustink

Hello FPC-Pascal,

you wrote 12 lines
> TMyClassPublished=class(TObject) > published > procedure MyProcedure; virtual; > end; > And a derived one: > TMyClassDerived=class(TMyClassPublished) > public > procedure MyProcedure; override; > end; > Is there any difference in the derived one with less visibility in the > method ? This means, does it use less/more memory, more/less calling > speed, more/less RTTI information, ... ?

MW> no, no, no, no
MW> You cannot lower visibility, since the following example is still possible: MW> var
MW> a:TMyClassPublished;
MW> begin
MW> a := TMyClassDerived.Create;
MW> a.MyProcedure;
MW> end;
MW> it will use the scope of a and not the "redefined" scope in TMyClassDerived

That was exactly my suspect, but as RTTI was in the game, maybe some differences happend.

I had found this "visibility lower" warnings all along the LCLfpgui interface, so I think I will move them to the expected "published" level as parent TWSxxx classes.

Best regards, José

Reply by email

Zaher Dirkey
to José Mejuto

What useful for put procedure in Publish?

José Mejuto wrote 41 lines
Hello FPC-Pascal, Thursday, April 15, 2010, 11:57:01 PM, you wrote: >> TMyClassPublished=class(TObject) >> published >>   procedure MyProcedure; virtual; >> end; >> And a derived one: >> TMyClassDerived=class(TMyClassPublished) >> public >>   procedure MyProcedure; override; >> end; >> Is there any difference in the derived one with less visibility in the >> method ? This means, does it use less/more memory, more/less calling >> speed, more/less RTTI information, ... ? MW> no, no, no, no MW> You cannot lower visibility, since the following example is still possible: MW> var MW>    a:TMyClassPublished; MW> begin MW>    a := TMyClassDerived.Create; MW>    a.MyProcedure; MW> end; MW> it will use the scope of a and not the "redefined" scope in TMyClassDerived That was exactly my suspect, but as RTTI was in the game, maybe some differences happend. I had found this "visibility lower" warnings all along the LCLfpgui interface, so I think I will move them to the expected "published" level as parent TWSxxx classes. -- Best regards,  José _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Zaher Dirkey

Reply by email

Flávio Etrusco
to José Mejuto
José Mejuto wrote 12 lines
Hello FPC-Pascal, Friday, April 16, 2010, 8:42:32 AM, you wrote: ZD> What useful for put procedure in Publish? I do not know :-? I'll ask in the Lazarus list. -- Best regards,  José

Published methods can be found with TObject.MethodAddress, that's how the lfm hook event handlers (and why Form event handlers are published).

Best regards,
Flávio

Reply by email

José Mejuto
to Flávio Etrusco

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é

Reply by email

Flávio Etrusco
to José Mejuto
José Mejuto wrote 19 lines
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.

Flávio

Reply by email

Marc Weustink
to Flávio Etrusco
Flávio Etrusco wrote 23 lines
On Fri, Apr 16, 2010 at 4:54 PM, José Mejuto 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

Marc

Reply by email

Martin
to Marc Weustink
Marc Weustink wrote 79 lines
Flávio Etrusco wrote: > On Fri, Apr 16, 2010 at 4:54 PM, José Mejuto 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

Reply by email

Zaher Dirkey
to Flávio Etrusco: Sure, I was just saying that in a different context. I found Marc's observation very…

2010/4/17 Flávio Etrusco :

Show quoted text 25 lines
On Fri, Apr 16, 2010 at 4:54 PM, José Mejuto 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. Flávio

Yes it is useful info for me,
Is that mean descending from TForm (or any class) without mentioned "published" or any of (public, protected, private) it will be considered as published?

Thanks

Zaher Dirkey

Reply by email

Mattias Gaertner
to Zaher Dirkey
Show quoted text 31 lines
2010/4/17 Flávio Etrusco : > On Fri, Apr 16, 2010 at 4:54 PM, José Mejuto 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. > > Flávio Yes it is useful info for me, Is that mean descending from TForm (or any class) without mentioned "published" or any of (public, protected, private) it will be considered as published?

Yes. If you want less published use the TCustomXXX, e.g. TCustomForm.

Mattias

Reply by email

Zaher Dirkey
to Mattias Gaertner
Mattias Gaertner wrote 38 lines
On Sat, 17 Apr 2010 13:05:07 +0200 Zaher Dirkey wrote: > 2010/4/17 Flávio Etrusco : > > On Fri, Apr 16, 2010 at 4:54 PM, José Mejuto 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. > > > > Flávio > > Yes it is useful info for me, > Is that mean descending from TForm (or any class) without mentioned > "published" or any of (public, protected, private) it will be > considered as published? Yes. If you want less published use the TCustomXXX, e.g. TCustomForm. Mattias

I meant

If i use, if i not mentioned "published"

TMyForm= class(TForm)
   procedure Method1;
end;

is is equal to

TMyForm= class(TForm)
published
   procedure Method1;
end;

Thanks in advance

Zaher Dirkey

Reply by email

Mattias Gaertner
to Zaher Dirkey
Show quoted text 55 lines
On Sat, Apr 17, 2010 at 1:08 PM, Mattias Gaertner wrote: > On Sat, 17 Apr 2010 13:05:07 +0200 > Zaher Dirkey wrote: > >> 2010/4/17 Flávio Etrusco : >> > On Fri, Apr 16, 2010 at 4:54 PM, José Mejuto 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. >> > >> > Flávio >> >> Yes it is useful info for me, >> Is that mean descending from TForm (or any class) without mentioned >> "published" or any of (public, protected, private) it will be >> considered as published? > > Yes. If you want less published use the TCustomXXX, e.g. TCustomForm. > > Mattias I meant If i use, if i not mentioned "published" TMyForm= class(TForm) procedure Method1; end; is is equal to TMyForm= class(TForm) published procedure Method1; end;

Yes, because TForm descends from TPersistent.
Normal classes have "private" as default visibility.

Mattias

Reply by email

Marc Weustink
to Martin: Interesting..... I thought (not even sure why I thought it, or were I pcked it up; so it…
Martin wrote 11 lines
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?
Your correct, thats why toyu are not allowed to use inherited in these
classes, but
   procedure TChild.Foo;
   begin
     TBaseClass(ClassParent).Foo;
     // do more
   end;

Marc

Reply by email