Link to home
Start Free TrialLog in
Avatar of scrapdog
scrapdogFlag for United States of America

asked on

Non-COM Interfaces

I think it is a design flaw in the Object Pascal language that interfaces are assumed to be mainly used for COM.

I have a few interfaces that I have written that I would like to use with some of my objects;  however, I am forced to implement the methods in IUnknown.  This is not a huge problem, but I do not want my objects to be reference counted.

I want each instance of my object to live until I tell it to die, regardless of whether or not there are any interface pointers pointing to it.

Therefore, my plan is to:

1.  Copy the implementation of QueryInterface from the QueryInterface of TInterfacedObject.
2.  Do nothing in _AddRef and _Release.


I am the only one who is going to be using the interfaces and objects.  I just want some advice on whether or not this is safe.

(btw, most of my classes in question inherit from TPersistent.  Inheriting from TInterfacedObject is not an option)
ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of scrapdog

ASKER

I do like the way Java does interfaces, but I know the way Delphi does them is much more powerful.  They just *seem* cobbled to fit COM and sometimes I am a bit apprehensive to use them without COM.

You answered my question, so here are the points!
Avatar of Madshi
Madshi

Hmmm... I don't know Java. What is better in Java's interface handling?

>> They just *seem* cobbled to fit COM

Why? Only because they like to implement reference counting? Delphi strings also use reference counting, dynamic arrays do, too.

Regards, Madshi.
>Hmmm... I don't know Java. What is better in Java's interface handling?

They're not BETTER, but they're simpler.

>Why?

Because if you look at the implementation of TInterfacedObject, you see all this ABCID and XYZID stuff, that's why. =)