Solved

Non-COM Interfaces

Posted on 2001-07-26
4
195 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

815 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now