Re: Interface Question
- From: Hans-Peter Diettrich <DrDiettrich1@xxxxxxx>
- Date: Mon, 09 Oct 2006 23:47:33 +0200
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.
Often it's desireable to get an idea, what object hides behind some small interface, as it might be interesting to know what object hides behind a Sender:TObject in an event handler. Once you get the object, you can retrieve its class type or name, and proceed accordingly. This procedure is safe, as long as the object is retrieved whenever needed, and no object reference is stored for later reuse.
DoDi
.
- Follow-Ups:
- Re: Interface Question
- From: Rob Kennedy
- 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
- 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
|