Re: Interface Question
- From: Hans-Peter Diettrich <DrDiettrich1@xxxxxxx>
- Date: Mon, 09 Oct 2006 16:27:22 +0200
Maarten Wiltink wrote:
Or is the
COM object of ObjectIF somehow re-created as an IPersistFile when
type-cast as such.
The object is never re-created.
(see below)
If I understand correctly, an interface
reference points to a VMT-like structure that includes the methods
prescribed by the interface. A classtype that implements multiple
interfaces simply builds several such tables from its 'master' VMT.
That's right, a Delphi classtype can include any number of interface descriptions. Such a description includes the VMT of the interface, and some more information that allows to reference the object from an interface reference.
I doubt that, in case of an OLE object, a single class incorporates all the interface "VMT"s. Instead I guess that either an object of a prefabricated class is created, which implements the requested interface, or that a classtype will be synthesized on-the-fly, which includes the requested interface. Or all calls of interface methods are translated by the compiler, into a form usable with OLE objects?
There's probably more to it as a reference through an interface type
must still be able to access the instance's fields, but this at least
explains some of it for me.
For the curious:
Every object includes an hidden VMT pointer (at offset zero), and for every implemented interface another hidden pointer to the interface description inside the classtype (below the VMT of the class). Casting an object to an interface returns the address of the interface-VMT-pointer in the object instance, at the known offset (stored in the interface description) in the instance. Prior to an access to an interface method, the interface reference is decremented by the same offset, resulting in an "ordinary" reference to the implementing object, so that it's methods can run with the correct Self reference. If you want to cast an interface reference into an object reference, simply implement an according interface method, which does nothing but Result := Self;
DoDi
.
- Follow-Ups:
- Re: Interface Question
- From: Maarten Wiltink
- Re: Interface Question
- References:
- Interface Question
- From: alanglloyd@xxxxxxx
- Re: Interface Question
- From: Maarten Wiltink
- Interface Question
- Prev by Date: Disabling an application during a file save?
- Next by Date: Re: Interface Question
- Previous by thread: Re: Interface Question
- Next by thread: Re: Interface Question
- Index(es):
Relevant Pages
|