Tech Tip: Object Property Null Value and its Type
PRODUCT: 4D | VERSION: 16 R4 | PLATFORM: Mac & Win
Published On: June 28, 2018
An object's property value can be assigned to Null. This can cause incosistencies when obtaining the type using Value type in results based on the database structure.
According to the documentation for OB Get
"In versions prior to v16 R4, when property contains a null value and if the type parameter is not used, 4D returns an empty string. For 4D v16 R4 and higher versions, the Is null constant is returned in this case. To preserve compatibilty, this change takes effect only if the "Use object notation to access objects properties (Unicode required)" option is enabled in the database (see the Compatibility page)."
Example Code that behaves differently based on Object Notation Setting:
C_OBJECT($test_ob) C_LONGINT($type_l) $test_ob:=New object("property";Null) $type_l:=Value type(OB Get($test_ob;"name")) Case of : ($type_l=Is null) // Object Notation is Enabled : ($type_l=Is text) // Object Notation is Disabled End case |
A safe way to check if the value is Null regardless of compatibility setting is to check if the value is Null