KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Preventing errors from an undefined object's boolean attribute
PRODUCT: 4D | VERSION: 18 | PLATFORM: Mac & Win
Published On: December 1, 2020

Objects are useful variables with the flexibility provided when trying to pass data. One of the potential uses of objects are to pass boolean values from one method to another.

An error can occur when attempting to check the boolean value and the attribute is not defined.
A way to prevent this is to pass the attribute into a BOOL() command. If a NULL value is passed the BOOL command will return a False. This will prevent any issues with seeing a NULL value instead of an expected boolean value of true or False.

For example, instead of the following:

C_OBJECT($myObject)

If($myObject.boolAttribute)
    $var:=True
Else
    $var:=False
End if


Add in Bool around the Object to be safe like below:
C_OBJECT($myObject)

If(Bool($myObject.boolAttribute))
   $var:=True
Else
   $var:=False
End if


In the first an error will occur due to $myObject.boolAttribute returning a NULL while the second will pass the NULL into the Bool command and return a False.