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 |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access