Re: Interface as Object. can I do this?

From: Ender (linuxmustdie_at_hotmeil.com)
Date: 10/23/03


Date: Thu, 23 Oct 2003 15:47:08 +0600


> | How can I convert a interface in a object?

Joanna Carter wrote:
> You can't apart from some very nasty hacking and you shouldn't.
>
> Google for threads on the topic of interfaces and object references,
> unless you don't value your sanity, use all interfaces or all objects,
> don't mix them without a lot of experience.

Because of interface reference counting using an object reference is
strictly not recomended. Taking an object reference from interface does not
raise RefCount for object, so object itself may be destroyed at any time
while you using it through object reference.

One of ways to prevent this, hold a collection of objects with RefCount set
at 1 on creation of object. That objects will never be destroyed through
interface reference counting. You may take interfaces from this objects at
any time, they should not interfere with object references.

I don't think that technique is "nasty hacking". Just other reference
counting strategy.



Relevant Pages

  • Re: How do I use a TOleServer derived object properly? (Yet another interface question).
    ... I think you're ok with using the object as an object reference, ... By the way, when you imported the TLB, did you tell it to support events? ... > TConnection = class ... > look like they're intended to implement the _IConnectionEvents interface ...
    (borland.public.delphi.language.objectpascal)
  • Re: Return collection interfaces or collection objects???
    ... I like returning an interface better than ... Create sone specific collection instance, ... dependancy - the caller will be returned an object reference and will ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: dynamic runtime casting?
    ... dynamic_cast is identical to the VB TryCast function - they both compile to ... interface on an object by name. ... All you have is a univeral object reference ...
    (microsoft.public.dotnet.languages.vc)
  • How do interface implementations work?
    ... When a class implements an interface, how can it access its fields from ... Normally, when you call a method on an object reference, the object ... reference gets passed in the EAX register, ...
    (borland.public.delphi.language.objectpascal)
  • Re: Interface as Object. can I do this?
    ... > interface reference counting. ... Obj: TMyInterfacedObject; ...
    (borland.public.delphi.language.objectpascal)