Skip to content

Instantly share code, notes, and snippets.

@martinusso
Created January 10, 2017 15:44
Show Gist options
  • Save martinusso/7542d7fd5b4e6dee47aec49291263f02 to your computer and use it in GitHub Desktop.
Save martinusso/7542d7fd5b4e6dee47aec49291263f02 to your computer and use it in GitHub Desktop.
Check if Variant is empty or null in Delphi
// uses System, Variants
function IsEmptyOrNull(const Value: Variant): Boolean;
begin
Result := VarIsClear(Value) or VarIsEmpty(Value) or VarIsNull(Value) or (VarCompareValue(Value, Unassigned) = vrEqual);
if (not Result) and VarIsStr(Value) then
Result := Value = '';
end;
@erdesigns-eu
Copy link

Exactly what i was looking for, thank you.

@mgcd-jed
Copy link

mgcd-jed commented Jul 13, 2023

In case your default values are 0 or another precise value :

if (not Result) and VarIsNumeric(Value) then
    Result := Value = 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment