Solved

Non-COM Interfaces

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

759 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

23 Experts available now in Live!

Get 1:1 Help Now