This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v20.6
OB Get
|
OB Get ( object ; property {; type} ) -> Function result | ||||||||
Parameter | Type | Description | ||||||
object | Object, Object Field |
![]() |
Structured object | |||||
property | Text |
![]() |
Name of property to read | |||||
type | Longint |
![]() |
Type to which to convert the value | |||||
Function result | Expression |
![]() |
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 or designate a 4D object field.
Note: This command supports attribute definitions in 4D Write Pro objects, like the WP GET ATTRIBUTES command (see example 9).
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 collection | Longint | 42 |
Is date | Longint | 4 |
Is longint | Longint | 9 |
Is null | Longint | 255 |
Is object | Longint | 38 |
Is picture | Longint | 3 |
Is pointer | Longint | 23 |
Is real | Longint | 1 |
Is text | Longint | 2 |
Is time | Longint | 11 |
The command returns the value of the property. Several types of data are supported. Note that:
Compatibility Notes:
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
When retrieving a date, the resulting value depends on the current database date settings.
C_OBJECT($object)
C_DATE($birthday)
C_TEXT($birthdayString)
OB SET($object;"Birthday";!30/01/2010!)
$birthday:=OB Get($object;"Birthday";Is date) //30/01/10
$birthdayString:=OB Get($object;"Birthday") //"2010-01-29T23:00:00.000Z" (Paris time zone)
C_OBJECT($object)
C_DATE($birthday)
OB SET($object;"Birthday";!30/01/2010!)
$birthday:=OB Get($object;"Birthday") //30/01/10, no need for Is date
Note: For more information on this setting, please refer to the Compatibility page.
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)
Recovery in 4D of a time stored in an object:
C_OBJECT($obj_o)
C_TIME($set_h;$get_h)
$set_h:=?01:00:00?+1
OB SET($obj_o;"myHour";$set_h)
// $obj_o = {"myHour":3601}
// The time is stored in seconds
$get_h:=OB Get($obj_o;"myHour";Is time)
// $get_h = ?01:00:01?
Examples of working with 4D object fields:
// Define a value
OB SET([People]Identity_OB;"First name";$firstName)
OB SET([People]Identity_OB;"Last name";$lastName)
// Get a value
$firstName:=OB Get([People]Identity_OB;"First name")
$lastName:=OB Get([People]Identity_OB;"Last name")
In the method of a form containing a 4D Write Pro area, you can write:
If(FORM Event=On Validate)
OB SET([MyDocuments]My4DWP;"myatt_Last edition by";Current user)
OB SET([MyDocuments]My4DWP;"myatt_Category";"Memo")
End if
You can also read custom attributes of the documents:
vAttrib:=OB Get([MyDocuments]My4DWP;"myatt_Last edition by")
You want to know the size of a picture stored in an object attribute:
C_LONGINT($vSize)
$vSize:=Picture size(OB Get($object;"photo";Is picture))
Note: If you assign the result of the command to a picture variable, the Is picture constant is not necessary. Example:
C_PICTURE($vPict)
$vPict:=OB Get($object;"photo") //"is picture" is useless in this case
Product: 4D
Theme: Objects (Language)
Number:
1224
Created: 4D v14
Modified: 4D v15
Modified: 4D v15 R4
Modified: 4D v16 R4
Modified: 4D v16 R6
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)