Sign in Join

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

Mailing lists / fpc-pascal / 2017-03

how to determine if a class has descendant registered within the current program

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Dennis

I have a many classes, one inherits from another one, in an ancestor method, I want to test whether the calling class is a childless class.

e.g.
class function TAncestor.GetCaption : String; //virtual
begin
     if HasChild then
       result := 'something'
   else
     result := 'something else';
end;

where HasChild is a boolean class function that tells me whether the current calling class has children defined or now.

Is that possible?

Dennis

Michael Van Canneyt
to Dennis
Dennis wrote 18 lines
I have a many classes, one inherits from another one, in an ancestor method, I want to test whether the calling class is a childless class. e.g. class function TAncestor.GetCaption : String; //virtual begin if HasChild then result := 'something' else result := 'something else'; end; where HasChild is a boolean class function that tells me whether the current calling class has children defined or now. Is that possible?

Currently not, but I think that Sven Barth will implement something for the new RTTI which will make this possible in the future.

Michael.

Graeme Geldenhuys
to Michael Van Canneyt
Michael Van Canneyt wrote
Currently not, but I think that Sven Barth will implement something for the new RTTI which will make this possible in the future.

That should be handy for the class documentation too, being able to list all descendants of a class (much like Java's JavaDoc does).

Regards,
Graeme

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 6 lines
On 2017-03-08 10:55, Michael Van Canneyt wrote: > Currently not, but I think that Sven Barth will implement something > for the new RTTI which will make this possible in the future. That should be handy for the class documentation too, being able to list all descendants of a class (much like Java's JavaDoc does).

Not really, because the list depends on a compiled binary. There is no binary when generating documentation...

The good news is that the documentation can already do this without any changes to the compiler; if so desired, it could generate a list of all descendents in the package.

Michael.

Graeme Geldenhuys
to Michael Van Canneyt
Michael Van Canneyt wrote
Not really, because the list depends on a compiled binary. There is no binary when generating documentation...

Ah, okay.

The good news is that the documentation can already do this without any changes to the compiler; if so desired, it could generate a list of all descendents in the package.

Indeed, I knew this would already be possible. I simply thought the RTTI option might be a bit more efficient.

Regards,
Graeme