Interfaces (Was: Multiple inheritance)_(re)

Fri, 30 May 1997 08:41:05 +0100


Hi,

Here's a simple example of how Delphi 3.0 implements interfaces. The main
difference between this and what Frank was suggesting is that Delphi 3.0
doesn't allow and fields in an interface. This is because COM is designed
to work across process and machine boundaries using remote procedure
calls(RPC) but does have support for remote variable calls(if there is such
a thing!) and this is the main reason for using interfaces...

this simple example of a Delphi interface is from a copy of a unit I'm
working on to use MS ActiveScripting.

the interface bit:
const
    SIID_IActiveScriptSiteWindow = '{D10F6761-83E9-11cf-8F20-00805F2CD064}';


type

  IActiveScriptSiteWindow = interface(IUnknown)
    [SIID_IActiveScriptSiteWindow]

      function GetWindow( out phwnd : HWND ):HResult; stdcall;
     function EnableModeless( fEnable : boolean ):HResult; stdcall;
  end;

a class that implements that interface:

  THostSite = class(TInterfacedObject, IActiveScriptSite, IActiveScriptSiteW
indow)
  public

    Shell : THostShell;

    constructor Create( pshell : THostShell );
    destructor Destroy; override;


    {** IActiveScriptSiteWindow **}
    function GetWindow( out phwnd : HWND ):HResult; stdcall;
    function EnableModeless( fEnable : boolean ):HResult; stdcall;

end;

The TInterfacedObject is the base object for the class and the
IActiveScriptSite and IActiveScriptSiteWindow are interfaces it supports.
You access an interface using the QueryInterface function in the IUnknown
interface from which all interfaces are derived by passing it the
interfaces IID.

Hope this is of some interest. Sorry about the formatting of the code...I
foolishly installed a beta of MS Outlook Express which doesn't like to put
spaces at the start of a line occasionally....

Dave
Dave Fiddes, CALM Software Production Officer
Department of Mathematics, Heriot-Watt University, Edinburgh
email D.J.Fiddes@hw.ac.uk - Tel: 0131-451-3251





David Fiddes (D.J.Fiddes@hw.ac.uk)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es