3.7.3 Variants and interfaces

Remark Dispatch interface support for variants is currently broken in the compiler.

Variants can contain a reference to an interface – a normal interface (descending from IInterface) or a dispatchinterface (descending from IDispatch). Variants containing a reference to a dispatch interface can be used to control the object behind it: the compiler will use late binding to perform the call to the dispatch interface: there will be no run-time checking of the function names and parameters or arguments given to the functions. The result type is also not checked. The compiler will simply insert code to make the dispatch call and retrieve the result.

This means basically, that you can do the following on Windows:

Var
  W : Variant;
  V : String;

begin
  W:=CreateOleObject('Word.Application');
  V:=W.Application.Version;
  Writeln('Installed version of MS Word is : ',V);
end;

The line

  V:=W.Application.Version;

is executed by inserting the necessary code to query the dispatch interface stored in the variant W, and execute the call if the needed dispatch information is found.