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
Variant
variables are initialized toUnassigned
. When you want to assign a value to aVariant
, but are unable to assign a specific, known value, useNull
to represent an unknown or missing value. In particular,TField
-derived components use theNull
value to represent SQL NULL values (when you want the field value as aVariant
).Variant
expressions that useNull
as an operand produce aNull
result.Attempting to convert a
Null
value to a number raises runtime error 15 (EVariantError
).Refer to
nil
for the equivalent ofNULL
in 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 |
Get Delphi in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.