Sign in Join

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

Mailing lists / fpc-pascal / 2015-08

IS operator and library created objects

6 messages · 6 people ·

Reply by email Subscribe to this list Your subscription

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

Fabio Luis Girardi

Hi!

Currently, I'm doing a small program that uses libraries, objects and the operator IS, that is know that this operator fails because of duplication of VMT.

Everyone know some alternative (or more elegant) method to test if a object created on a library is a class descendant without use object.ClassName? Or in case of use String to check the class name, how retrieve the class name of all descendant classes from a object?

The best regards, Fabio Luis Girardi PascalSCADA Project http://sourceforge.net/projects/pascalscada http://www.pascalscada.com
Sven Barth
to Fabio Luis Girardi
"Fabio Luis Girardi" wrote
Currently, I'm doing a small program that uses libraries, objects and the

operator IS, that is know that this operator fails because of duplication of VMT.

And /that/ is one of the reasons why dynamic packages were invented...

Everyone know some alternative (or more elegant) method to test if a

object created on a library is a class descendant without use object.ClassName? Or in case of use String to check the class name, how retrieve the class name of all descendant classes from a object?

Nope, there is no more elegant way. And you'll probably need to walk the class tree using ParentClass and retrieve each name.

Note: an except-handler will suffer from the same problem if it needs to catch an exception that was raised from the library (or the other way round).
You are going to a extreme fragile direction there.

Regards,
Sven

Torsten Bonde Christiansen
to Sven Barth
Sven Barth wrote 24 lines
Am 20.08.2015 03:42 schrieb "Fabio Luis Girardi" < >: > Currently, I'm doing a small program that uses libraries, objects and the operator IS, that is know that this operator fails because of duplication of VMT. And /that/ is one of the reasons why dynamic packages were invented... > > Everyone know some alternative (or more elegant) method to test if a object created on a library is a class descendant without use object.ClassName? Or in case of use String to check the class name, how retrieve the class name of all descendant classes from a object? > Nope, there is no more elegant way. And you'll probably need to walk the class tree using ParentClass and retrieve each name. Note: an except-handler will suffer from the same problem if it needs to catch an exception that was raised from the library (or the other way round). You are going to a extreme fragile direction there.

What about TObject.InheritsFrom(aclass : tclass) - Is that not the equivalent of the *IS* operator

-Torsten.

Michael Van Canneyt
to Torsten Bonde Christiansen
Torsten Bonde Christiansen wrote 27 lines
On 2015-08-20 08:06, Sven Barth wrote: > > Am 20.08.2015 03:42 schrieb "Fabio Luis Girardi" < > >: > > Currently, I'm doing a small program that uses libraries, objects and the > operator IS, that is know that this operator fails because of duplication > of VMT. > > And /that/ is one of the reasons why dynamic packages were invented... > > > > > Everyone know some alternative (or more elegant) method to test if a > object created on a library is a class descendant without use > object.ClassName? Or in case of use String to check the class name, how > retrieve the class name of all descendant classes from a object? > > > > Nope, there is no more elegant way. And you'll probably need to walk the > class tree using ParentClass and retrieve each name. > > Note: an except-handler will suffer from the same problem if it needs to > catch an exception that was raised from the library (or the other way > round). > You are going to a extreme fragile direction there. > What about TObject.InheritsFrom(aclass : tclass) - Is that not the equivalent of the *IS* operator

It is, but will suffer from the same problem.
The library has a completely separate VMT and inheritance tree from the calling program.

You need dynamically loadable packages for this to work.

Michael.

Michael Schnell
to Fabio Luis Girardi: Hi! Currently, I'm doing a small program that uses libraries, objects and the operator…
Fabio Luis Girardi wrote
Everyone know some alternative (or more elegant)...

AFAIK FPC does not support using objects (er even strings) cross a dynamic library interface.

Delphi has "Runtime Packages" for this. But those are not (yet) implemented in fpc (which would need to do that for all OSes)

So you need to do "flat" library calls: no objects, no strings, ...

-Michael

Mark Morgan Lloyd
to Michael Schnell
Michael Schnell wrote 6 lines
On 08/20/2015 03:42 AM, Fabio Luis Girardi wrote: > > Everyone know some alternative (or more elegant)... AFAIK FPC does not support using objects (er even strings) cross a dynamic library interface.

Unless you explicitly use the cmem library. However even then it's basically restricted to passing/returning strings as procedure parameters/results.

Delphi has "Runtime Packages" for this. But those are not (yet) implemented in fpc (which would need to do that for all OSes) So you need to do "flat" library calls: no objects, no strings, ...
Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]