Name

IDispatch Interface

Syntax

type
  IDispatch = interface(IUnknown)
  ['{00020400-0000-0000-C000-000000000046}']
    function GetTypeInfoCount(out Count: Integer): HResult; stdcall;
    function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo):
      HResult; stdcall;
    function GetIDsOfNames(const IID: TGUID; Names: Pointer;
      NameCount, LocaleID: Integer; DispIDs: Pointer):
      HResult; stdcall;
    function Invoke(DispID: Integer; const IID: TGUID;
      LocaleID: Integer; Flags: Word; var Params;
      VarResult, ExcepInfo, ArgErr: Pointer): HResult; stdcall;
  end;

Description

IDispatch is a standard ActiveX interface that lets you call a COM method without knowing the method’s name, arguments, or return type at compile time.

Tips and Tricks

  • When you use a COM object that implements the IDispatch interface, Delphi automatically takes care of all the details involved in calling a method dynamically. You can store the object reference in a Variant variable or use a dispinterface type.

  • To write a COM server that implements the IDispatch interface, simply derive your class from TAutoObject (in the ComObj unit) or one of its descendants. If you are using Delphi’s type library editor, simply check the box for the Dual flag, and let Delphi handle the details for you.

  • See the Windows Platform SDK documentation to learn more about the IDispatch interface.

See Also

Dispinterface Keyword, Interface Keyword, IUnknown Interface, VarDispProc Variable, Variant Type

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.