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

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

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

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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

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

Michael Van Canneyt


On Wed, 8 Mar 2017, Dennis wrote:

> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

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

Graeme Geldenhuys-6
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).

Regards,
  Graeme

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

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

Michael Van Canneyt


On Wed, 8 Mar 2017, Graeme Geldenhuys wrote:

> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

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

Graeme Geldenhuys-6
On 2017-03-08 11:43, 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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal