Re: Interface Question
- From: Rob Kennedy <me3@xxxxxxxxxxx>
- Date: Mon, 09 Oct 2006 23:11:14 -0500
Hans-Peter Diettrich wrote:
Maarten Wiltink wrote:
[...] If you want to cast an interface reference into an object
reference, simply implement an according interface method, which
does nothing but Result := Self;
It's not considered good style, however. Once you're doing things
through interfaces, you shouldn't go back to object references lest
you save one somewhere and it collapses under your feet because the
original interface reference went out of scope somewhere else and
the reference counting kicked in.
That's right, but there exist special cases.
One may want to use the objects in the first place, but needs interfaces for some "external" requirement. Then refcounting can be disabled in the object, what makes them live until they are explicitly destroyed, as usual. Otherwise it certainly is not a good idea, to store object references for reference counted objects.
But note that you can't *fully* disable reference counting. You can change _Release to not destroy the object, but you can't tell the compiler not to call _AddRef and _Release at all. So if you free the object by calling Free, you need to be certain that there are no dangling interface references for that object. If there are, then _AddRef or _Release will eventually be called for the object that has already been destroyed, and that's the same problem you have even if you _don't_ "disable" reference counting.
--
Rob
.
- Follow-Ups:
- Re: Interface Question
- From: Hans-Peter Diettrich
- Re: Interface Question
- References:
- Interface Question
- From: alanglloyd@xxxxxxx
- Re: Interface Question
- From: Maarten Wiltink
- Re: Interface Question
- From: Hans-Peter Diettrich
- Re: Interface Question
- From: Maarten Wiltink
- Re: Interface Question
- From: Hans-Peter Diettrich
- Interface Question
- Prev by Date: Re: Interface Question
- Next by Date: Re: Disabling an application during a file save?
- Previous by thread: Re: Interface Question
- Next by thread: Re: Interface Question
- Index(es):
Relevant Pages
|