views:

174

answers:

1

Working in Delphi7 just now, I noticed that not only a VarIsEmpty function exists, but also a VarIsEmptyParam.

Since the help of Delphi does not give much explanation:

VarIsEmptyParam returns true if the given variant represents an unassigned optional parameter.

If the variant contains any other value, the function result is false.

I was just wondering if anyone has used this function, and if so, how this function is meant to be used.

+7  A: 

In COM it is possible to have optional parameters in a method call at any position, while in Delphi this is only possible at the end. So if you want to omit the parameter you can write EmptyParam instead. EmptyParam is a global variable initialized with the correct values.

Now when you are implementing a COM interface you have to deal with these optional parameters, too. The way to find out these omitted parameters is VarIsEmptyParam.

Note that even an empty variant given as a parameter yields VarIsEmptyParam = false, because the param is not omitted. It is just empty, but it is there.

So normally there is:

VarIsEmpty(v) ==> not VarIsEmptyParam(v)

and

VarIsEmptyParam(v) ==> not VarIsEmpty(v)
Uwe Raabe
`EmptyParam` has a variant type of `varError` with an error value of `Var_ParamNotFound`, whereas an empty variant is one with a variant type of `varEmpty`. Two completely different kinds of data, just with similar names.
Rob Kennedy