4D introduces a new Null type to ease the management of objects and collections. Thanks to the null value, you can represent a missing value and easily verify if your object or collection is correctly set.
The null type represents an unknown or a missing value.This type is special because it is impossible to cast to the null type or declare a variable of this type and it can be used just with object, collection, pointer and picture variables.
Be careful not to confuse the null value with an empty string or an integer with 0 for example, since 0 or “” are values.
Null is very useful in the case of a collection. Let’s examine a concrete example: since the the collection elements are not typed by default, it ain’t possible for 4D to set the elements with default values. No panic; Null value to the rescue!
C_COLLECTION($c)
$c:=New collection
$c[3]:=10
//Results
//$c[0]=null
//$c[1]=null
//$c[2]=null
//$c[3]=10
How to set a null value?
You can simply use the new command: Null.
C_OBJECT($o)
$o:=New object
$o.quantity:=Null
How to test null Values?
You can test null values with the Null command:
If ($o.quantity=Null)
ALERT("Please enter a quantity")
end if