[fpc-pascal] IS operator and library created objects
Michael Van Canneyt
michael at freepascal.org
Thu Aug 20 08:50:25 CEST 2015
On Thu, 20 Aug 2015, Torsten Bonde Christiansen wrote:
> On 2015-08-20 08:06, Sven Barth wrote:
>>
>> Am 20.08.2015 03:42 schrieb "Fabio Luis Girardi" <fluisgirardi at gmail.com
>> <mailto:fluisgirardi at gmail.com>>:
>> > 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.
More information about the fpc-pascal
mailing list