Null Values
A Null value means that the value of a field, variable or parameter is undefined. Variables and parameters are implicitly initialized to Null when they are declared. For String or Struct data types, Uniface provides some special handling.
For string variables, Null
values are interpreted as an empty string (""
). For Struct variables, NULL is
interpreted as a collection of references to zero Structs.
Uniface implicitly converts the data type whenever necessary, for example, when assignments are made between non-matching data types, so the way Null values are interpreted can change.
For example, Null fields are saved into XML streams as empty elements. This means that a null field is indistinguishable from an empty string. When an empty element is loaded into a numeric field it is converted into a zero numeric value.
Example: Assigning Values to Struct Members
The following example assigns variables to Struct members and shows the effect that Null values can have on the Struct.
variables any vAny ; Implicitly initialized to NULL struct vStruct1, vStruct2 ; Implicitly initialized to NULL, but interpreted string vString ; Implicitly initialized to NULL. but interpreted as "" endvariables vStruct1->x = vAny vStruct1->y = "" vStruct1->z = vString vStruct1->x = vStruct2 vStruct1->y = vStruct2->z
- For Struct variables, NULL is interpreted as or a collection of references to zero Structs.
-
vStruct1
is implicitly initialized to an empty Struct, and now gets one member namedx
, whose value is NULL. This is because the value of the vAny variable is NULL. - Another member, named
y
, is added to the Struct. Its value is also NULL because an empty Struct member is initialized to NULL - Another member, named
z
, is added to the Struct. Although the real value is NULL,vString
is a string variable, so the value is an empty string (a String with zero length). -
vStruct1
no longer has any members named x because x has been replaced by the contents of vStruct2. Since it is a struct with a NULL value, it is interpreted as being a list of zero references to Structs. -
vStruct1
no longer has members namedy
either. BecausevStruct2
has zero members namedz
,vStruct1
now also has zero members at the targety
.