Null Variable
Variant
variables are initialized to
Unassigned
. When you want to assign a value to a
Variant
, but are unable to assign a specific,
known value, use Null
to represent an unknown or
missing value. In particular, TField
-derived
components use the Null
value to represent SQL
NULL values (when you want the field value as a
Variant
).
Variant
expressions that use
Null
as an operand produce a
Null
result.
Attempting to convert a Null
value to a number
raises runtime error 15 (EVariantError
).
Refer to nil
for the equivalent of
NULL
in C and C++.
// In the Variant array Data, compute the average of all // non-Null values. function ComputeAverage(Data: Variant): Variant; var Sum: Double; Count: Integer; I: Integer; begin Sum := 0.0; Count := 0; for I := VarArrayLowBound(Data) to VarArrayHighBound(Data) do if not VarIsNull(Data[I]) then begin Sum := Sum + Data[I]; Inc(Count); end; if Count = 0 then Result := Null else Result := Sum / Count; end;