This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v20.6
Null

Null 


 

Null -> Function result 
Parameter Type   Description
Function result  Null in Null value

Null returns the Null type value null.

This function allows you to assign or compare the null value to the following language elements:

Language elementsComments
object property valuesComparing Null to an object property returns true if the property value is null, and false otherwise. To simplify code, comparing Null also returns true if the property does not exist in the object (i.e. is Undefined), see example 4. 
collection elementsWhen a collection is expanded by adding non-adjacent elements, any intermediary elements get automatically the null value.
object variables (C_OBJECT)See (*) below
collection variables (C_COLLECTION)See (*) below
pointer variables (C_POINTER)See (*) below
picture variables (C_PICTURE)(*) Assigning the null value to such a variable type clears its contents. In this case, it has the same effect as calling the CLEAR VARIABLE command.
variant variables (C_VARIANT)

Note: This command cannot be used with scalar database fields. Null values in database fields are managed by the SQL engine, and are handled through the Is field value Null and SET FIELD VALUE NULL commands,

You want to assign and test the null value to an object property:

 C_OBJECT(vEmp)
 vEmp:=New object
 vEmp.name:="Smith"
 vEmp.children:=Null
 
 If(vEmp.children=Null//true
 End if
 If(vEmp.name=Null//false
 End if
 If(vEmp.parent=Null//true
 End if

Note: This example requires that the object notation is activated in the database.

You want to assign and compare the null value to a collection element:

 C_COLLECTION(myCol)
 myCol:=New collection(10;20;Null)
 ...
 If(myCol[2]=Null)
  // if the 3rd element is null
    ...
 End if

These examples show the various ways to assign or compare the null value to variables: 

  //Object variable
 C_OBJECT($o)
 $o:=New object
 $o:=Null //equivalent to CLEAR VARIABLE($o)
 If($o#Null//equivalent to If (OB Is defined($o))
 End if

  //Collection variable
 C_COLLECTION($c)
 $c:=New collection
 $c:=Null //equivalent to CLEAR VARIABLE($c)
 If($c#Null)
 End if

  //Pointer variable
 C_POINTER($p)
 $p:=->$v
 $p:=Null //equivalent to CLEAR VARIABLE($p)
 If($p=Null//equivalent to If (Is Nil pointer($p))
 End if

  //Picture variable
 C_PICTURE($i)
 $i:=$vpicture
 $i:=Null //equivalent to CLEAR VARIABLE($i)
 If($i#Null//equivalent to If (Picture size($i)#0)
 End if

Here are the different results of the Undefined command as well as the Null command with object properties, depending on the context:

 C_OBJECT(vEmp)
 vEmp:=New object
 vEmp.name:="Smith"
 vEmp.children:=Null
 
 $undefined:=Undefined(vEmp.name) // False
 $null:=(vEmp.name=Null//False
 
 $undefined:=Undefined(vEmp.children) // False
 $null:=(vEmp.children=Null//True
 
 $undefined:=Undefined(vEmp.parent) // True
 $null:=(vEmp.parent=Null//True



See also 

Is field value Null
OB SET NULL
SET FIELD VALUE NULL

 
PROPERTIES 

Product: 4D
Theme: Language
Number: 1517

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v16 R4

 
ARTICLE USAGE

4D Language Reference ( 4D v20)
4D Language Reference ( 4D v20.1)
4D Language Reference ( 4D v20.2)
4D Language Reference ( 4D v20.3)
4D Language Reference ( 4D v20.4)
4D Language Reference ( 4D v20.5)
4D Language Reference ( 4D v20.6)