Board index » delphi » Interfaces Beginner

Interfaces Beginner


2006-01-20 04:55:19 PM
delphi95
All my experience of interfaces are with Java, which I fully understand, and
I think I have got the basics of with Delphi, but a couple of things still
worry me. I am sure there are a lot more but here we go:
1. In Java if Implementation2 extends Implementation1, and a class
implements Implementation2, then the class must have all the methods defined
in both implemntations. But In Delphi, I understand that I have to use some
thing like:
MyClass=Class(Implementation2, Implementation1)...
Do I really need to mention both implmentations?
2. What is the GUID I see all over the place for?
3. What is reference counting?
TIA
David McCallum.
 
 

Re:Interfaces Beginner

"David McCallum" <XXXX@XXXXX.COM>a écrit dans le message
de news: XXXX@XXXXX.COM...
| All my experience of interfaces are with Java, which I fully understand,
and
| I think I have got the basics of with Delphi, but a couple of things still
| worry me. I am sure there are a lot more but here we go:
You have to understand that Delphi interface, prior to .NET, use the COM
pattern, even if the interfaces are not for COM support.
| 1. In Java if Implementation2 extends Implementation1, and a class
| implements Implementation2, then the class must have all the methods
defined
| in both implemntations. But In Delphi, I understand that I have to use
some
| thing like:
|
| MyClass=Class(Implementation2, Implementation1)...
|
| Do I really need to mention both implmentations?
Yes, this is a requirement of the COM spec :-( However, if you implement the
base interface in one class and then implement the derived interface in a
derived class, then you only need to mention the derived interface in the
declaration of the derived class.
| 2. What is the GUID I see all over the place for?
Because Delphi uses the COM model, it relies on the GUID for its uniqueness
of identity. If you don't include a GUID in an interface declaration then
you can not cast or use "as" to cast to another interface. You also can not cast
an interface back to the underlying object. Once again :-(
| 3. What is reference counting?
Reference counting is meant to allow the "server" COM object to free itself
when the last interface reference to it falls out of scope. Don't forget
that Delphi doesn't support garbage collection. Most of us who use
interfaces in Delphi use reference counting as a poor-man's garbage
collection as a side effect.
OTOH, interfaces in Delphi for .NET do not require GUIDs or implement
reference counting. They are designed primarily as a language feature, not
primarily as a COM feature that also gives you a language feature. Much more
like the Java way of doing things.
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
 

Re:Interfaces Beginner

Joanna.
A couple more:
COM??? Do you have alink which explains this. I have seen it mentioned many
times.
GUID: I still don't fully understand this, again any links would be handy.
My idea is I have a collection of TPanels, which have to implement an
interface, do I need all of this additional info...
David.
 

Re:Interfaces Beginner

"David McCallum" <XXXX@XXXXX.COM>a écrit dans le message
de news: 43d0bba3$XXXX@XXXXX.COM...
| COM??? Do you have alink which explains this. I have seen it mentioned many
| times.
|
| GUID: I still don't fully understand this, again any links would be handy.
community.borland.com/article/1,1410,20384,00.html
This link answers quite a few questions. Let us know if there are more :-)
| My idea is I have a collection of TPanels, which have to implement an
| interface, do I need all of this additional info...
TPanel derives from TComponent which implements a non-reference-counted
version of IInterface which allows you to add interfaces to derived classes.
_AddRef, _Release and QueryInterface are all implemented for you but you
will have to declare a GUID on your interface.
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
 

Re:Interfaces Beginner

On Fri, 20 Jan 2006 12:34:58 -0000, Joanna Carter [TeamB] writes:
Quote
TPanel derives from TComponent which implements a non-reference-counted
version of IInterface which allows you to add interfaces to derived classes.
_AddRef, _Release and QueryInterface are all implemented for you but you
will have to declare a GUID on your interface.
Or have Delphi do it for you by pressing ctrl+shift+g
--
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com
 

Re:Interfaces Beginner

Joanna Carter [TeamB] writes:
Quote
You have to understand that Delphi interface, prior to .NET, use the COM
pattern, even if the interfaces are not for COM support.
Isn't this only for D5 and earlier. When Kylix was released, it used
the same technology as the Delphi 6 compiler. Kylix definately doesn't
have COM, and if I remeber correctly, Interfaces in Delphi 6 and up are not
bound to COM anymore. (I will see if I can find that link on BDN)
Regards,
- Graeme -
 

Re:Interfaces Beginner

Quote
Interfaces in Delphi 6 and up are not bound to COM anymore.
That's not what she said :-) The *pattern* is that of COM interfaces. You can
override that, but it takes extra work. Compare that with the way interfaces
work in Java and .NET where they are a purer language feature.
Cheers,
Jim Cooper
_____________________________________________
Jim Cooper XXXX@XXXXX.COM
Skype : jim.cooper
Singapore mobile: +65 9345 0024
Tabdee Ltd www.tabdee.ltd.uk
TurboSync - Connecting Delphi to your Palm
_____________________________________________