Tech Tip: Dot Notation with 4D OB commands
PRODUCT: 4D | VERSION: 16Rx | PLATFORM: Mac & Win
Published On: October 23, 2017
4D v16R4 introduced dot notation for objects and collections allowing for 4D code to be more flexible to use. While dot notation is an efficient and more elegant method of code writing it may not be parsed as such in all cases.
For example if the following is our goal:
C_OBJECT($var_ob) $var_ob:=New object $var_ob.sub1:=New object $var_ob.sub1.subA:="Value" |
to get the following results:
and if object notation is attempted to be used in the OB GET and OB SET command's second parameter as such:
C_OBJECT($var_ob) $var_ob:=New object $var_ob.sub1:=New object OB SET($var_ob;"sub1.subA";"Value 1") |
the second parameter will be considered as a whole singular property since the parameter accepts a string and dots are considered a valid character for a property name and results in:
Which is correct as the code above is effectively the same as:
C_OBJECT($var_ob) $var_ob:=New object $var_ob.sub1:=New object $var_ob["sub1.sub2"]:="Value 1" |
Instead to properly use the OB SET command dot notation must only be applied where 4D can expect a 4D Object or Collection such as the first parameter:
C_OBJECT($var_ob) $var_ob:=New object $var_ob.sub1:=New object OB SET($var_ob.sub1;"subA";"Value 1") |