Board index » delphi » Is it possible to use virtual and override in COM

Is it possible to use virtual and override in COM

Hi,

Below is a hypothetical scenario with COM interfaces. It's pretty easy to do
when just using Delphi classes, but I don't know how to do it with COM.
Normally it would require the virtual and override directives after the
function declarations.

Let's say we have four interfaces, IBase, IDesc1, IDesc2 and IDesc3 The
parent interface of IBase is IUnknown. IBase has one function Calculate,
which takes to arguments, A and B of type integer. It returns and integer
type as well. When called, IBase adds A and B and returns that value.
IDesc1+2+3 all has IBase as their parent interface. They will each do one of
the following things with the Calculate function:
1) Not implement it all and just let IBase return the value.
2) Override Calculate, call the inherited calculate (which would then set
result:=A+B), multiply the current value of result (which should be A+B) by
A (e.g. result:=result*A) and finally return that result (which would then
be result:=(A+B)*A).
3) Override Calculate and make it's entirely own implementation of the
function.

When you don't do anything special to the interface, you have to do number
three when implementing a descending interface. I know that number one is
possible (just think about the interfaces you normally descent from; you
don't have to implement every function there). Number two is the most
difficult, and I can't seem to find out how to use these added directives. I
can't see why it shouldn't be possible, since it would severely limit the OO
capabilites of COM.

I hope someone can help me, as it feels like I've run my head against a wall
:)

Thank you in advance

Regards
Anders Schack Petersen

 

Re:Is it possible to use virtual and override in COM


<<Anders Schack Petersen:
IDesc1+2+3 all has IBase as their parent interface. They
will each do one of the following things with the Calculate
function:
1) Not implement it all and just let IBase return the
value.

Quote

*No* interfaces ever implement anything: your question
makes no sense, sorry. Objects implement interfaces, in
whatever way they like. If your interface looks like this:
  IMYIntf = interface(IUnknown)
    procedure Paint;
  end;
all that that interface requires is that an implementing
object should have a Paint method. You could have any
number of objects that implement it in many different ways
- you might put code to format the hard disc in an
implementing object's Paint method, if you wanted. If you
have another interface,
  IMYChildIntf = interface(IMYIntf)
    procedure Draw;
  end;
all that that interface requires is that an implementing
object should have a Paint method and a Draw method - it
doesn't care what they do. Implementation is up to your
implementing objects, which can use all the usual
techniques of inheritance, containment, aggregation, etc.

--
Deborah Pate (TeamB) http://delphi-jedi.org

  Use Borland servers; TeamB don't see posts via ISPs
  http://www.borland.com/newsgroups/genl_faqs.html

Re:Is it possible to use virtual and override in COM


Dear Deborah

Thanks for clearing up a few things. I was aware of some of what you wrote,
but putting down my wishes on a piece of paper is difficult, but I'll give
it another shot ;-)

An object, ObjBase, implements an interface, IBase, that has one function
Calculate. In ObjBase, is it possible to add the virtual directive to
Calculate, and let e.g. a C++ programmer import the COM object and keep
working on it by overriding my function, and preferably using some of the
functionality I implemented?

It's soooo hard to explain when you've got only about 85% overview of the
technology :-(

I understand that I can use whatever OO techniques I please inside Delphi,
but what's possible with multiple languages.

Once again, thanks in advance.
Regards
Anders Schack Petersen

Re:Is it possible to use virtual and override in COM


<<Anders Schack Petersen:
I understand that I can use whatever OO techniques I please
inside Delphi, but what's possible with multiple languages.

Quote

The implementing objects you make in Delphi are like any
other objects you make - so no, you can't inherit from them
and override their methods in C++. You could presumably
create a C++ object that contained an IMyIntf object and
implemented IMyChildIntf itself, using the internal object
where appropriate.

--
Deborah Pate (TeamB) http://delphi-jedi.org

  Use Borland servers; TeamB don't see posts via ISPs
  http://www.borland.com/newsgroups/genl_faqs.html

Re:Is it possible to use virtual and override in COM


Hi

Thanks for clearing up the last piece of confusion.
It seems I'll have to stay within delphi, but I assume I can still do my OO
bit by just deriving from the Com object I wish (e.g. TAutoObject).
Thanks again.

Regards
Anders Schack Petersen
"Deborah Pate (TeamB)" <d.p...@cableinet.co.not-this-bit.uk> wrote in
message news:VA.00000250.006a7e11@cableinet.co.not-this-bit.uk...

Quote
> <<Anders Schack Petersen:
> I understand that I can use whatever OO techniques I please
> inside Delphi, but what's possible with multiple languages.

> The implementing objects you make in Delphi are like any
> other objects you make - so no, you can't inherit from them
> and override their methods in C++. You could presumably
> create a C++ object that contained an IMyIntf object and
> implemented IMyChildIntf itself, using the internal object
> where appropriate.

> --
> Deborah Pate (TeamB) http://delphi-jedi.org

>   Use Borland servers; TeamB don't see posts via ISPs
>   http://www.borland.com/newsgroups/genl_faqs.html

Other Threads