Solved

Non-COM Interfaces

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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 …

828 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