Skip to main content

VarIsClear

function VarIsClear(const V: Variant): Boolean;

Example

procedure ScriptEvent(var Value: variant);
var
Candidate: Variant;
begin
Candidate := Unassigned;
Value := VarIsClear(Candidate); // True
end;

Usage

VarIsClear tests whether a Variant is Empty, contains a nil interface or reports a custom clear state.

Parameters and result

ItemTypeDescription
VVariant (const)Value to inspect without conversion. Variant indirection is resolved by the Velox helper.
ResultBooleanTrue for Empty, a nil varDispatch/varUnknown interface, or a custom Variant whose IsClear handler returns True; otherwise False.

Important distinctions

  • Null is assigned and therefore is not clear. Use VarIsNull when Null means missing in the data contract.
  • Empty text, zero, false and an empty but allocated Variant array are not clear.
  • VarIsEmpty is narrower: it recognises only varEmpty, not a nil interface or custom clear value.
  • VarIsClear does not coerce a value before testing. Text such as 'NULL' or '0' remains ordinary non-clear text.

Additional Technical Info

VarIsClear returns True when V has no usable assigned value under Delphi's broader clear-state test. It includes Empty/Unassigned Variants, nil interface Variants and custom Variant types whose handler reports that the value is clear.

The example is fictional and source-reviewed only.

Implementation

The modified PascalScript runtime registers Delphi System.Variants.VarIsClear directly. Delphi resolves Variant/by-reference Variant indirection, then checks the stored type. Built-in varEmpty is clear. Built-in varDispatch and varUnknown values are clear only when their interface pointer is nil. A registered custom Variant type delegates the decision to its IsClear method.

Side effects, errors and concurrency

The built-in checks only read V and do not allocate or mutate state. A custom Variant type's handler is code supplied by that type; any cost, side effect or exception from that handler propagates through this call. Independent built-in checks are safe to perform concurrently provided the same Variant storage is not being mutated at the same time.

Related entries

  • VarIsEmpty tests exactly Empty/Unassigned.
  • VarIsNull tests exactly Null.
  • VarType exposes the raw type code when the distinction must be handled explicitly.

External references

Created 2026-07-15