4D v14.3

OB Get

Home

 
4D v14.3
OB Get

OB Get 


 

OB Get ( object ; property {; type} ) -> Function result 
Parameter Type   Description
object  Object in Structured object
property  Text in Name of property to read
type  Longint in Type to which to convert the value
Function result  Boolean, Date, Object, Pointer, Real, Text in Current value of property

The OB Get command returns the current value of the property of the object, optionally converted into the type specified.

object must have been defined using the C_OBJECT command.

In the property parameter, pass the label of the property to be read. Note that the property parameter is case sensitive.  

By default, 4D returns the value of the property in its original type. You can "force" the typing of the value returned using the optional type parameter. To do this, in type you pass one of the following constants found in the Field and Variable Types theme:

Constant Type Value
Is Boolean Longint 6
Is date Longint 4
Is integer Longint 8
Is integer 64 bits Longint 25
Is JSON null Longint 255
Is LongInt Longint 9
Is object Longint 38
Is real Longint 1
Is string var Longint 24
Is text Longint 2
Is time Longint 11
Object array Longint 39

The command returns the value of the property. Several types of data are supported. Note that:

  • a pointer is returned as such; it can be evaluated using the JSON Stringify command,
  • dates are returned in the format "\"YYYY-MM-DDTHH:mm:ssZ\""
  • in real values, the decimal separator is always a period "."
  • times are returned as a number (seconds for 4D, milliseconds for JSON).

Retrieving a text type value:

 C_OBJECT($ref)
 C_TEXT($FirstName)
 OB SET($ref;"FirstName";"Harry")
 $FirstName:=OB Get($ref;"FirstName") // $FirstName = "Harry" (text)

Retrieving a real number value converted into a longint:

 OB SET($ref ;"age";42)
 $age:=OB Get($ref ;"age") // $age is a real number (default)
 $age:=OB Get($ref ;"age";Is LongInt// $age is a longint

Retrieving the values of an object:

 C_OBJECT($ref1;$ref2)
 OB SET($ref1;"LastName";"Smith") // $ref1={"LastName":"Smith"}
 OB SET($ref2;"son";$ref1// $ref2={"son":{"LastName":"Smith"}}
 $son:=OB Get($ref2;"son") // $son={"LastName":"john"} (object)
 $sonsName:=OB Get($son ;"name") // $sonsName="john" (text)

Modifying the age of an employee twice:

 C_OBJECT($ref_john;$ref_jim)
 OB SET($ref_john;"name";"John";"age";35)
 OB SET($ref_jim;"name";"Jim";"age";40)
 APPEND TO ARRAY($myArray;$ref_john// we create an object array
 APPEND TO ARRAY($myArray;$ref_jim)
  // we change the age for John from 35 to 25
 OB SET($myArray{1};"age";25)
  // We replace the age of "John" in the array
 For($i;1;Size of array($myArray))
    If(OB Get($myArray{$i};"name")="John")
       OB SET($myArray{$i};"age";36) // instead of 25
  // $ref_john={"name":"John","age":36}
    End if
 End for

Deserializing a data string formatted in ISO:

 C_OBJECT($object)
 C_DATE($birthday)
 C_TEXT($birthdayString)
 OB SET($object;"Birthday";"1990-12-25T12:00:00Z")
 $birthdayString:=OB Get($object;"Birthday")
  // $birthdayString="1990-12-25T12:00:00Z"
 $birthday:=OB Get($object;"Birthday";Is date)
  // $birthday=25/12/90

Using nested objects:

 C_OBJECT($ref1;$child;$children)
 C_TEXT($childName)
 OB SET($ref1;"firstname";"John";"lastname";"Monroe")
  //{"firstname":"john","lastname";"Monroe"}
 OB SET($children;"children";$ref1)
 $child:=OB Get($children;"children")
  //$son = {"firstname":"John","lastname":"Monroe"} (object)
 $childName:=OB Get($child;"lastname")
  //$childName = "Monroe" (text)
  //or
 $childName:=OB Get(OB Get($children;"children");"lastname")
  // $childName = "Monroe" (text)

 
PROPERTIES 

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

 
HISTORY 

New
Created: 4D v14

 
SEE ALSO 

Field and Variable Types
OB Copy

 
ARTICLE USAGE

4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)