It is recommended to use VarIsClear to check is Variant is Null, Empty or Unassigned. But I found function can return False while variable Unassigned in debugger if varByRef flag is set. VarIsClear checking
function VarIsClear(const V: Variant): Boolean;
var
LHandler: TCustomVariantType;
LVarData: TVarData;
begin
LVarData := FindVarData(V)^;
with LVarData do
if VType < CFirstUserType then
Result := (VType = varEmpty) or
(((VType = varDispatch) or (VType = varUnknown)) and
(VDispatch = nil))
else if FindCustomVariantType(VType, LHandler) then
Result := LHandler.IsClear(LVarData)
else
Result := False;
end;
and VType in my case is 16384 ($4000 = varByRef). How to check is it Null, Empty or Unassigned properly?
VarIsEmpty. VarIsClear. VarIsNull. So it seems that you need VarIsEmpty since you wish to check for an unassigned variant.
According to the documentation your variant type of VT_EMPTY | VT_BYREF is invalid. This is explicitly called out in this text:
The VT_EMPTY and VT_NULL values MUST NOT be specified with the VT_BYREF bit flag.
So this means that your variant is invalid and it is not reasonable to expect anything of the RTL functions when they are presented with invalid input.
I suspect you'll need to either fix the code that serves up this invalid variant, or work around the broken code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With