Skip to main content
Version: v20 R2 BETA


Variables, fields or expressions of the Object type can contain various types of data. The structure of native 4D objects is based on the classic principle of "property/value" pairs. The syntax of these objects is based on JSON notation:

  • A property name is always a text, for example "Name". It must follow specific rules.

  • A property value can be of the following type:

    • number (Real, Integer, etc.)
    • text
    • null
    • boolean
    • pointer (stored as such, evaluated using the JSON Stringify command or when copying),
    • date (date type or ISO date format string)
    • object(1) (objects can be nested on several levels)
    • picture(2)
    • collection

(1)ORDA objects such as entities or entity selections cannot be stored in object fields; however, they are fully supported in object variables in memory.

(2)When exposed as text in the debugger or exported to JSON, picture object properties print "[object Picture]".


Keep in mind that property names differentiate between upper and lower case.

You manage Object type variables, fields or expressions using the object notation or the commands available in the Objects (Language) theme. Note that specific commands of the Queries theme such as QUERY BY ATTRIBUTE, QUERY SELECTION BY ATTRIBUTE, or ORDER BY ATTRIBUTE can be used to carry out processing on object fields.

Each property value accessed through the object notation is considered an expression. You can use such values wherever 4D expressions are expected:

  • in 4D code, either written in the methods (Code Editor) or externalized (formulas, 4D tags files processed by PROCESS 4D TAGS or the Web Server, export files, 4D Write Pro documents...),
  • in the Expression areas of the Debugger and the Runtime explorer,
  • in the Property list of the Form editor for form objects: Variable or Expression field as well as various selection list box and columns expressions (Data Source, background color, style, or font color).


Objects must have been instantiated, otherwise trying to read or modify their properties will generate a syntax error.

Object instantiation can be done in one of the following ways:

  • using the New object command,
  • using the {} operator.

Several 4D commands and functions return objects, for example Get database measures or File. In this case, it is not necessary to instantiate explicitely the object, the 4D language does it for you.

New object command

The New object command creates a new empty or prefilled object and returns its reference.


 var $obVar : Object //declaration of an object type 4D variable
$obVar:=New object //instantiation of an object and assignment to the 4D variable

var $obFilled : Object
$obFilled:=New object("name";"Smith";"age";42) //instantiation and assignment of a prefilled object

{} operator

The {} operator allows you to create an object literal. An object literal is a semi-column separated list of zero or more pairs of property names and associated values of an object, enclosed in curly braces ({}). The object literal syntax creates empty or filled objects.

Since any property value is considered an expression, you can create sub-objects using {} in property values. You can also create and reference collection literals.


 var $o ; $o2 ; $o3 : Object //declaration of object variables
$o := {} // instantiation of an empty object
$o2 := {a: "foo"; b: 42; c: {}; d: ($toto) ? true : false } // instantiation of an object
// with properties {"a":"foo","b":42,"c":{},"d":false})

// same properties using variables
var $a : Text
var $b : Number
var $c : Object
$o3:={ a: $a; b: $b; c: $c } // {"a":"foo";b":42;"c":{}}

You can mix the New object and literal syntaxes:

ob1: {age: 42}; \
ob2: New object("message"; "Hello"); \
form1: Formula(return This.ob1.age+10); \
form2 : Formula(ALERT($1)); \
col: [1; 2; 3; 4; 5; 6]\

$o.form1() //52
$o.form2($o.ob2.message) // displays Hello
$col:=$o.col[5] //6

Regular or shared object

You can create two types of objects:

  • regular (non-shared) objects, using the New object command or object literal syntax ({}). These objects can be edited without any specific access control but cannot be shared between processes.
  • shared objects, using the New shared object command. These objects can be shared between processes, including preemptive threads. Access to these objects is controlled by Use...End use structures. For more information, refer to the Shared objects and collections section.

Syntax basics

Object notation can be used to access object property values through a chain of tokens.

Object properties

With object notation, object properties can be accessed in two ways:

  • using a "dot" symbol:


  • using a string within square brackets:



//or also:

Since an object property value can be an object or a collection, object notation accepts a sequence of symbols to access sub-properties, for example:


Object notation is available on any language element that can contains or returns an object, i.e:

  • Objects themselves (stored in variables, fields, object properties, object arrays, or collection elements). Examples:
     $age:=$myObjVar.employee.age //variable
$addr:=[Emp]data_obj.address //field
$city:=$ //property of an object
$pop:=$aObjCountries{2}.population //object array
$val:=$myCollection[3].subvalue //collection element
  • 4D commands that return objects. Example:
     $measures:=Get database measures.DB.tables
  • Project methods that return objects. Example:
      // MyMethod1
#DECLARE -> $o : Object
$o:=New object("a";10;"b";20)

$result:=MyMethod1.a //10
  • Collections Example:
     myColl.length //size of the collection


Preliminary Note: Since objects are always passed by reference, there is usually no need to use pointers. While just passing the object, internally 4D automatically uses a mechanism similar to a pointer, minimizing memory need and allowing you to modify the parameter and to return modifications. As a result, you should not need to use pointers. However, in case you want to use pointers, property values can be accessed through pointers.

Using object notation with pointers is very similar to using object notation directly with objects, except that the "dot" symbol must be omitted.

  • Direct access:


  • Access by name:



 var vObj : Object
var vPtr : Pointer
vObj:=New object
x:=vPtr->a //x=10

Null value

When using the object notation, the null value is supported though the Null command. This command can be used to assign or compare the null value to object properties or collection elements, for example:

For more information, please refer to Null and Undefined.

Undefined value

Evaluating an object property can sometimes produce an undefined value. Typically when trying to read or assign undefined expressions, 4D will generate errors. This does not happen in the following cases:

  • Reading a property of an undefined object or value returns undefined; assigning an undefined value to variables (except arrays) has the same effect as calling CLEAR VARIABLE with them:
     var $o : Object
var $val : Integer
$val:=10 //$val=10
$val:=$o.a //$o.a is undefined (no error), and assigning this value clears the variable
  • Reading the length property of an undefined collection produces 0:
     var $c : Collection //variable created but no collection is defined
$size:=$c.length //$size = 0
  • An undefined value passed as parameter to a project method is automatically converted to 0 or "" according to the declared parameter type.
     var $o : Object
mymethod($o.a) //pass an undefined parameter

//In mymethod method
#Declare ($myText : Text) //parameter type is text
// $myText contains ""
  • A condition expression is automatically converted to false when evaluating to undefined with the If and Case of keywords:
     var $o : Object
If($o.a) // false
End if
Case of
:($o.a) // false
End case
  • Assigning an undefined value to an existing object property reinitializes or clears its value, depending on its type:
  • Object, collection, pointer: Null
  • Picture: Empty picture
  • Boolean: False
  • String: ""
  • Number: 0
  • Date: !00-00-00! if "Use date type instead of ISO date format in objects" setting is enabled, otherwise ""
  • Time: 0 (number of ms)
  • Undefined, Null: no change
     var $o : Object
$o:=New object("a";2)
$o.a:=$o.b //$o.a=0
  • Assigning an undefined value to a non existing object property does nothing.

When expressions of a given type are expected in your 4D code, you can make sure they have the correct type even when evaluated to undefined by surrounding them with the appropriate 4D cast command: String, Num, Date, Time, Bool. These commands return an empty value of the specified type when the expression evaluates to undefined. For example:

 $myString:=Lowercase(String($o.a.b)) //make sure you get a string value even if undefined
//to avoid errors in the code

For more information, please refer to Null and Undefined


Using object notation simplifies the 4D code while handling objects. Note however that the command-based notation is still fully supported.

  • Writing and reading objects (this example compares object notation and command notation):
  // Using the object notation
var $myObj : Object //declares a 4D variable object
$myObj:={} //creates an object literal and assigns it to the variable
$age:=$myObj.age //56

// Using the command notation
var $myObj2 : Object //declares a 4D variable object
OB SET($myObj2;"age";42) //creates an object and adds the age property
$age:=OB Get($myObj2;"age") //42

// Of course, both notations can be mixed
var $myObj3 : Object
OB SET($myObj3;"age";10)
$age:=$myObj3.age //10
  • Create a property and assign values, including objects:
 var $Emp : Object
$Emp:=New object
$"London" //creates the city property and sets its value to "London"
$"Paris" //modifies the city property
$ object("office";"123456789";"home";"0011223344")
//creates the phone property and sets its value to an object
  • Get a value in a sub-object is very simple using the object notation:
 $vCity:=$ //"Paris"
$vPhone:=$ //"0011223344"
  • You can access properties as strings using the [ ] operator
 $Emp["city"]:="Berlin" //modifies the city property
//this can be useful for creating properties through variables
var $addr : Text
End for
// creates 4 empty properties "address1...address4" in the $Emp object