Board index » delphi » Can anything done about incompatible interfaces

Can anything done about incompatible interfaces

Based on the advice of someone here, I built my whole approach on having one
program being able to call any of a number of interchangeable COM Servers
based on identical interfaces with different GUIDs.  At the crucial point of
creating the COM object, I use the following code.

      Case AMDServerID of
        3 : Server := AMDDaylight_TLB.CoAMDData.CreateRemote(LocalMachine);
        4 : Server := AMDSchedUAll_TLB.CoAMDData.CreateRemote(LocalMachine);
      end;

Server is simply declared IAMDData.  Apparently it is the AMDDaylight_TLB
IAMDData that is being used because I get an incompatible type error on the
AMDSchedUAll_TLB line.  The interfaces really are identical in every way
except the GUIDs, which had to be different in order to allow the interfaces
to be both registered at the same time.

This was the first point where I was actually trying to incorporate two
interfaces at the same time, so its the first time the problem has cropped
up.  Is there any way around the problem or is a total rework needed and
weeks of work are down the drain?
--
Please respond only in the newsgroup.  I will not respond
to newsgroup messages by e-mail.

 

Re:Can anything done about incompatible interfaces


"Bj?rge S?ther" <REMOVE_bsaether@THIS_online.no> skrev i melding
news:3918a617@dnews...

Quote
> IBasic = interface(IUnknown)
> ['{4F8FB400-1AA9-11D4-A656-0000C0A8D864}']
>   procedure DoSomething; safecall;
> end;

> IBasic_A = interface(IUnknown)
> ['{4F8FB401-1AA9-11D4-A656-0000C0A8D864}']
>   procedure DoSomething; safecall;
> end;

> IBasic_B = interface(IUnknown)
> ['{4F8FB402-1AA9-11D4-A656-0000C0A8D864}']
>   procedure DoSomething; safecall;
> end;

> TBasic_A = class(TInterfacedObject, IBasic_A)
>   procedure DoSomething; safecall;
> end;

> TBasic_B = class(TInterfacedObject, IBasic_B)
>   procedure DoSomething; safecall;
> end;

Oops ! Sorry, What I meant, was:

- Show quoted text -

Quote
> IBasic = interface(IUnknown)
> ['{4F8FB400-1AA9-11D4-A656-0000C0A8D864}']
>   procedure DoSomething; safecall;
> end;

> IBasic_A = interface(IBasic)
> ['{4F8FB401-1AA9-11D4-A656-0000C0A8D864}']
>   procedure DoSomething; safecall;
> end;

> IBasic_B = interface(IBasic)
> ['{4F8FB402-1AA9-11D4-A656-0000C0A8D864}']
>   procedure DoSomething; safecall;
> end;

> TBasic_A = class(TInterfacedObject, IBasic_A)
>   procedure DoSomething; safecall;
> end;

> TBasic_B = class(TInterfacedObject, IBasic_B)
>   procedure DoSomething; safecall;
> end;

--
Bjoerge Saether
Consultant / Developer
Asker, Norway
bsaether.removet...@online.no (remove the obvious)

Re:Can anything done about incompatible interfaces


"Mark Reichert" <m...@messagelink.com> skrev i melding news:39188add@dnews...

Quote
>The interfaces really are identical in every way
> except the GUIDs, which had to be different in order to allow the
interfaces
> to be both registered at the same time.

> This was the first point where I was actually trying to incorporate two
> interfaces at the same time, so its the first time the problem has cropped
> up.  Is there any way around the problem or is a total rework needed and
> weeks of work are down the drain?

Hi !

You may typecast interfaces, and you may inherit interfaces. One solution
might be to create one basic interface, and let the specific ones descend
from this with different GUIDs, without adding any fields. An example:

IBasic = interface(IUnknown)
['{4F8FB400-1AA9-11D4-A656-0000C0A8D864}']
  procedure DoSomething; safecall;
end;

IBasic_A = interface(IUnknown)
['{4F8FB401-1AA9-11D4-A656-0000C0A8D864}']
  procedure DoSomething; safecall;
end;

IBasic_B = interface(IUnknown)
['{4F8FB402-1AA9-11D4-A656-0000C0A8D864}']
  procedure DoSomething; safecall;
end;

TBasic_A = class(TInterfacedObject, IBasic_A)
  procedure DoSomething; safecall;
end;

TBasic_B = class(TInterfacedObject, IBasic_B)
  procedure DoSomething; safecall;
end;

...now, when retrieving the interface, use the basic interface, it's
compatible with descendants, as with classes:

procedure Testit;
var
  Intf: IBasic;
begin
  case something of
    somevalue: Intf:=CoBasic_A.CreateRemote();
    othervalue: Intf:=CoBasic_B.CreateRemote();
  end;
end;

--
Bjoerge Saether
Consultant / Developer
Asker, Norway
bsaether.removet...@online.no (remove the obvious)

Re:Can anything done about incompatible interfaces


Quote
Bj?rge S?ther <REMOVE_bsaether@THIS_online.no> wrote in message

news:3918a617@dnews...

Quote
> You may typecast interfaces, and you may inherit interfaces. One solution
> might be to create one basic interface, and let the specific ones descend
> from this with different GUIDs, without adding any fields. An example:

Thanks for the confirmation.  That will save the situation, though it will
mean rework, and I don't know yet if I can still use the type library editor
to create the interfaces.
--
Please respond only in the newsgroup.  I will not respond
to newsgroup messages by e-mail.

Other Threads