4D v16.3

OB SET ARRAY

Home

 
4D v16.3
OB SET ARRAY

OB SET ARRAY 


 

OB SET ARRAY ( object ; property ; array ) 
Parameter Type   Description
object  Object, Object Field in Structured object
property  Text in Name of property to set
array  Text array, Real array, Boolean array, Object array, Pointer array, Longint array in Array to store in property

The OB SET ARRAY command defines the array to be associated with the property in the language object designated by the object parameter.

object must have been defined using the C_OBJECT command or designate a 4D object field.

In the property parameter, pass the label of the property to be created or modified. If the property already exists in object, its value is updated. If it does not exist, it is created.
Note that the property parameter is case sensitive. 

In the array parameter, pass the array that must be passed as the property value. Several array types are supported.

Note: It is not possible to use two-dimensional arrays.

Using a text array:

 C_OBJECT($Children)
 ARRAY TEXT($arrChildren;3)
 $arrChildren{1}:="Richard"
 $arrChildren{2}:="Susan"
 $arrChildren{3}:="James"
 
 OB SET ARRAY($Children;"Children";$arrChildren)
  // Value of $Children = {"Children":["Richard","Susan","James"]}

Adding an element to an array:

 ARRAY TEXT($arrText;2)
 $arrText{1}:="Smith"
 $arrText{2}:="White"
 C_OBJECT($Employees)
 OB SET ARRAY($Employees;"Employees";$arrText)
 APPEND TO ARRAY($arrText;"Brown") // Add to the 4D array
  // $Employees = {"Employees":["Smith","White"]}
 
 OB SET ARRAY($Employees;"Employees";$arrText)
  // $Employees = {"Employees":["Smith","White","Brown"]}

Using a text array with selection of an element:

  // $Employees = {"Employees":["Smith","White","Brown"]}
 OB SET ARRAY($Employees ;"Manager";$arrText{1})
  // $Employees = {"Employees":["Smith","White","Brown"],"Manager":["Smith"]}

Using an object array:

 C_OBJECT($Children;$ref_richard;$ref_susan;$ref_james)
 ARRAY OBJECT($arrChildren;0)
 OB SET($ref_richard;"nom";"Richard";"age";7)
 APPEND TO ARRAY($arrChildren;$ref_richard)
 OB SET($ref_susan;"name";"Susan";"age";4)
 APPEND TO ARRAY($arrChildren;$ref_susan)
 OB SET($ref_james;"name";"James";"age";3)
 
 APPEND TO ARRAY($arrChildren;$ref_james)
 
  // $arrChildren {1} = {"name":"Richard","age":7}
  // $arrChildren {2} = {"name":"Susan","age":4}
  // $arrChildren {3} = {"name":"James","age":3}
 
 OB SET ARRAY($Children;"Children";$arrChildren)
 
  // $Children = {"Children":[{"name":"Richard","age":7},{"name":"Susan",
  // "age":4},{"name":"James","age":3}]}

Here is how the object appears in the debugger:

Using an Object field:

 ARRAY TEXT($arrGirls;3)
 $arrGirls{1}:="Emma"
 $arrGirls{2}:="Susan"
 $arrGirls{3}:="Jamie"
 OB SET ARRAY([People]Children;"Girls";$arrGirls)



See also 

OB GET ARRAY
OB SET

 
PROPERTIES 

Product: 4D
Theme: Objects (Language)
Number: 1227

This command can be run in preemptive processes

 
HISTORY 

Created: 4D v14
Modified: 4D v15

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)