Comparison with an Undefined Value

Since the appearance of ORDA, classes, and other objects, you must work increasingly with undefined values.

Since some of you are asking for an easier way to use them, starting with v20, you can compare any type of value to an undefined value without throwing an error.

Usually, in 4D, the comparison operators =, #, >, <, >=, and <= check each operand’s type and value. If the types of the two operands are different, the comparison throws an error:

As mentioned before, we understand that when working with classes and objects, you must work with undefined values, so we have made this rule more flexible. Starting with v20, you can compare undefined values with all variable types:

  • The = comparison returns true when you compare an undefined variable with a null or undefined value and false in all the other ways:
$o:=new object
If ($o.undefined =10)
  ...
else
  // returns false because $o.undefined is undefined
  ...
End if
  • The # comparison returns false when you compare an undefined variable with a null or undefined value and true in all the other ways:
$o:=new object
If ($o.undefined #10)
  // returns true because $o.undefined is undefined
  ...
else
  ...
End if
  • The >, <, >= and <= comparisons return false for all the comparisons between an undefined variable and a scalar value (numeric, text, date, time, boolean). Because the comparison has no meaning, 4D throws an error for the other types.
$o:=new object
If ($o.undefined >10)
  ...
else
  // returns false because $o.undefined is undefined
  ...
End if

Check out the documentation for more details!

Fabrice Mainguené
• Product Owner •Fabrice Mainguené joined 4D Program team in November, 2016. As a Product Owner, he is in charge of writing the user stories then translating it to functional specifications. His role is also to make sure that the feature implementation delivered is meeting the customer need.After obtaining a Bachelor degree in Computer Science at CNAM, Fabrice joined a small software publishing company as a Windev developer. Then he worked for different companies in industry and trade areas as a Windev and web developer as well as technical advisor on new features.