Solved

Non-COM Interfaces

Posted on 2001-07-26
4
197 Views
Last Modified: 2010-04-06
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)
0
Comment
Question by:scrapdog
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 50 total points
ID: 6325823
>> I think it is a design flaw in the Object Pascal language that interfaces are assumed to be mainly used for COM.

I think you're wrong. Look, Kylix (Delphi for Linux) also supports interfaces, but no COM. Perhaps interfaces were primarely designed to support COM, but they were made more flexible right from the beginning. I'm using interfaces in all my components/packages without any COM and it's a joy...   :-)

You can do what you said (leaving _AddRef and _Release empty). I've done that thing and a lot of other hacks with _AddRef and _Release and everything works just beautifully...

Regards, Madshi.
0
 
LVL 5

Author Comment

by:scrapdog
ID: 6325864
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!
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6325922
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.
0
 
LVL 5

Author Comment

by:scrapdog
ID: 6327984
>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. =)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question