KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using Pointers to Tables in Object Literals
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: October 14, 2024

Object literals are a shorthand for creating objects with initial values that was introduced in 4D v20. This feature is useful to lessen the amount of code as well as make the code more readable. For example, you may have code such as:

$object:=New object()
$object.attr:=15

It can be shortened to the following object literal:

$object := {attr : 15}

One instance that one may find to be a challenge is when attempting to insert a pointer to a table as an attribute of an object. Due to a conflict between object literals and collection literals that use the square brackets, the following will create a syntax error:

$object:={pointer: ->[Table]}

This can be amended with the use of parenthesis:

$object:={pointer: (->[Table])}