What is the difference between the VarIsEmpty and VarIsEmptyParam functions
Asked Answered
P

1

7

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.

Pleura answered 8/3, 2010 at 13:9 Comment(0)
N
8

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)
Nixie answered 8/3, 2010 at 13:46 Comment(1)
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.Butanol

© 2022 - 2024 — McMap. All rights reserved.