Name
Null Variable
Syntax
var Null: Variant;
Description
The Null variable is the Null
Variant value. You should not change its
value.
Tips and Tricks
Variantvariables are initialized toUnassigned. When you want to assign a value to aVariant, but are unable to assign a specific, known value, useNullto represent an unknown or missing value. In particular,TField-derived components use theNullvalue to represent SQL NULL values (when you want the field value as aVariant).Variantexpressions that useNullas an operand produce aNullresult.Attempting to convert a
Nullvalue to a number raises runtime error 15 (EVariantError).Refer to
nilfor the equivalent ofNULLin C and C++.
Example
// 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;See Also
| EmptyParam Variable, Unassigned Variable, Variant Type, VarIsNull Function |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access