EmptyParam Variable
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.
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;