Board index » delphi » Derive a COM class from another COM class

Derive a COM class from another COM class

Hi,

How to derive a new COM class from a another COM class ?
Can BCB handle that ? How make the new class appear in the TLE ?

Mickael.

 

Re:Derive a COM class from another COM class


All my experience has been with Delphi.  But I'd think there'd be something
similar with BCB...

In a type library, you have define an interface to inherit from another
interface.  This is done through the ParentInterface field on the Attributes
tab when an Interface is selected in the Type Library editor.  You need to
ensure that, if the ParentInterface is defined in another type library, that
you're referencing it in the type library containing the interface (again,
this is done in the Uses tab in the Type Librray editor in Delphi when the
Type Library is selected).  This will allow you to inherit an interface.

Likewise, you can inherit an implementation object if you want it to support
your interface.  This is quite common in Delphi.  For example, if I want to
define a new Automation object, I'll have my implementation object inherit
from TAutoObject.  What this gives me is a component that automatically
supports the IUnknown and IDispatch interfaces.  So all I need to worry
about is the custom Automation interface I'm defining.

I'm not sure if I'm addressing your exact question.  I'm not sure if you're
after an Interface inheritance or an implementation object inheritance.  Let
me know if I've missed something. :)

Thanks,
Ed

Quote
Mickael Faivre-Macon wrote in message <8flpso$3...@bornews.borland.com>...
>Hi,

>How to derive a new COM class from a another COM class ?
>Can BCB handle that ? How make the new class appear in the TLE ?

>Mickael.

Re:Derive a COM class from another COM class


Hi Ed,

Thanks for your reply.

Quote
>I'm not sure if I'm addressing your exact question.  I'm not sure if you're
>after an Interface inheritance or an implementation object inheritance.

If I set the parent interface I will inherit this interface, but the class
will be abstract....
I would like to not have to reimplement all the methods of my previous
object.
Do you know how to get a complete implementation object inheritance ?

Mickael.

Re:Derive a COM class from another COM class


Mickael Faivre-Macon <faiv...@acer.net> escribi?en el mensaje de noticias
8flpso$3...@bornews.borland.com...

Quote
> Hi,

> How to derive a new COM class from a another COM class ?
> Can BCB handle that ? How make the new class appear in the TLE ?

> Mickael.

First, I'm sorry but I don't speak English very well.
With Delphi I know that you can derive a new COM class from another one, I
believe it's the same in BCB.
With an example (In Delphi):
You have the interface IMyInterface and the coclass TMyInterface =
class(TAutoObject, IMyInterface). Then, you
defines in the type library IDerivedMyInterface and the coclass
TDerivedMyInterface = class( TMyInterface, IDerivedMyInterface). You only
must implement the methods of IDerivedMyInterface. Other stuff very
important is you must remove:

// initialization section
initialization
  TAutoObjectFactory.Create(ComServer, TDerivedMyInterface,
Class_DerivedMyInterface,
    ciMultiInstance, tmBoth);

for the parent class. If you don't make this then you don't be able register
the DLL or EXE. I don't know why.

I hope help you, and apologyze my bad English.

Re:Derive a COM class from another COM class


Quote
> I would like to not have to reimplement all the methods of my previous
> object.
> Do you know how to get a complete implementation object inheritance ?

You should use delegation. Have a look at the implements directive and have
a look in Delphi's help under the topic "Implementing interfaces by
delegation"
__________________________________
Angelos Arampatzis
Computer Team S.A., Thessaloniki, Greece
agge...@cteam.the.forthnet.gr

The minimum could be defined as the perfection that an artifact achieves
when it is no longer possible to improve it by subtraction.
This is the quality that an object has when every component, every detail,
and every junction has been reduced or condensed to the essentials.
It is the result of the omission of the inessentials.

Re:Derive a COM class from another COM class


Quote
>I would like to not have to reimplement all the methods of my previous
>object.
>Do you know how to get a complete implementation object inheritance ?

OK, we are talking about the implementation object inheritance. :)

And again, I'm coming at this from Delphi... I'm assuming that it can be
done in BCB as well (please tell me if this is a false assumption...)

As alluded to by Federico, you can do a straight inheritance.  In Delphi, I
can define a class,

TMyObj = class(TAutoObject)
...

Because I'm inheriting from TAutoObject, I don't have to implement any
IUnknown or IDispatch functions.  TAutoObject does it for me.  Taking this
tack, you can define a superclass that supports your custom interface.
Then, your implementation objects can inherit from your superclass.  They
will be able to support your custom interface.

Another option is supporting your interface via delegation (Angelos'
suggestion).  In Delphi, you can define a class that supports an interface
(same as the superclass in the above example).  The difference is instead of
an implementation object inheriting from the superclass, it defines a
property of the superclass' type.  It's probably better to refer to the help
for a more complete explaination of delegation, as there are a few ways of
configuring this.  This is also something new in Delphi 5.  I don't know if
it's supported in BCB or not.

Ed

Other Threads