Name

EmptyParam Variable

Syntax

var EmptyParam: OleVariant;

Description

Some COM servers have optional parameters, which you can omit from the method call. In Delphi, however, the interface and dispatch interface declarations do not support optional parameters. You can call a method with optional parameters by using a Variant or by passing EmptyParam as the parameter value. If you have an interface or dispatch interface, you should use the interface instead of using a Variant because you gain the advantage of compile-time checking.

The default value of EmptyParam is a varError, with an error code value of Disp_E_ParamNotFound. You can change the value, but you should have a good reason to do so.

Example

The ShellWindows COM object has the Item method, which takes an optional Index parameter. Delphi implements the optional parameter by declaring two overloaded methods. The implementation of one method passes EmptyParam as the index value:

// The following is an excerpt from shdocvw.pas
function  TShellWindows.Item: IDispatch;
begin
  Result := DefaultInterface.Item(EmptyParam);
end;

function  TShellWindows.Item(index: OleVariant): IDispatch;
begin
  Result := DefaultInterface.Item(index);
end;

See Also

Dispinterface Keyword, Interface Keyword, OleVariant 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.