Board index » delphi » Getting 'Interface not supported' error

Getting 'Interface not supported' error

When doing the following I get an 'Inteface not supported' error - why is
this ?

var
  M1 : I1;
begin
  M1 := CreateComObject(CLASS_S2) as I1;
end;

Where S2 is a CoClass that implements an interface I2 which is defined in
the TypeLib as having its parent interface as I1;

If I change the above to the following :-

  M1 := CreateComObject(CLASS_I2) as I2;

Then the assignment passes, but surely M1 now points to an I2 interface and
if I try and do :-

  M1 := M1 as I1;

I again get the 'Inteface not supported' error - Why ?

Thanks for any help,
    Dave T.

 

Re:Getting 'Interface not supported' error


  If you create an S2 coclass, you *should* be expecting an I2 interface.
Why would you use the S2 coclass if you want the I1 interface?  Create an S1
coclass instead, or else go ahead and define M1 as type I2, and live with an
I2 interface...since it descends from the I1 interface, it has the same
abilities (and more), right?
-Howard

Re:Getting 'Interface not supported' error


Having a parent interface of I1 does not necessarily mean that your coclass
supports I1, directly. If you want to expose it's I1'ness, you have to
manually add I1 to the class implementation:

TFoo = class (TAutoObject, I2, I1)

Of course, this is all assuming that I1 is registered and marshalable.

have fun
--
Binh Ly
http://www.techvanguards.com

Quote
"Dave Taylor" <d...@davetaylor2.freeserve.co.uk> wrote in message

news:946nl2$6195@bornews.inprise.com...
Quote
> When doing the following I get an 'Inteface not supported' error - why is
> this ?

> var
>   M1 : I1;
> begin
>   M1 := CreateComObject(CLASS_S2) as I1;
> end;

> Where S2 is a CoClass that implements an interface I2 which is defined in
> the TypeLib as having its parent interface as I1;

> If I change the above to the following :-

>   M1 := CreateComObject(CLASS_I2) as I2;

> Then the assignment passes, but surely M1 now points to an I2 interface
and
> if I try and do :-

>   M1 := M1 as I1;

> I again get the 'Inteface not supported' error - Why ?

> Thanks for any help,
>     Dave T.

Re:Getting 'Interface not supported' error


Many thanks Binh, what you suggested works as I would have expected it to in
the first place.

Just briefly to answer Howards point ie. WHY ?

My interface I1 is to be implemented by more than one automation server, but
I want a client to be able to create an instance of any of these servers and
subsequently talk to it as though it were just an I1 interface.

Thanks again for your help,

    Dave T.

Quote
Binh Ly <b...@techvanguards.com> wrote in message news:3a66f332$1_2@dnews...
> Having a parent interface of I1 does not necessarily mean that your
coclass
> supports I1, directly. If you want to expose it's I1'ness, you have to
> manually add I1 to the class implementation:

> TFoo = class (TAutoObject, I2, I1)

> Of course, this is all assuming that I1 is registered and marshalable.

> have fun
> --
> Binh Ly
> http://www.techvanguards.com

> "Dave Taylor" <d...@davetaylor2.freeserve.co.uk> wrote in message
> news:946nl2$6195@bornews.inprise.com...
> > When doing the following I get an 'Inteface not supported' error - why
is
> > this ?

> > var
> >   M1 : I1;
> > begin
> >   M1 := CreateComObject(CLASS_S2) as I1;
> > end;

> > Where S2 is a CoClass that implements an interface I2 which is defined
in
> > the TypeLib as having its parent interface as I1;

> > If I change the above to the following :-

> >   M1 := CreateComObject(CLASS_I2) as I2;

> > Then the assignment passes, but surely M1 now points to an I2 interface
> and
> > if I try and do :-

> >   M1 := M1 as I1;

> > I again get the 'Inteface not supported' error - Why ?

> > Thanks for any help,
> >     Dave T.

Other Threads