KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Debugging and the 4DIF Transformation Tag
PRODUCT: 4D | VERSION: 14 R4 | PLATFORM: Mac & Win
Published On: July 23, 2015

4D Transformation Tags, 4D HTML Tags prior to 4D v14 R4, are tremendously powerful and versatile. With power comes the need to know what the possibilities are of some practices and good programming practices to avoid difficult to debug errors.

Consider the tags 4DIF and 4DELSEIF. The documentation states:

The <!--#4DIF expression--> comment offers the possibility to execute portions of code conditionally. The expression parameter can contain any valid 4D expression returning a Boolean value. In case of an interpretation error, the text “<!--#4DIF expression-->: A boolean expression was expected” is inserted instead of the contents located between <!--#4DIF --> and <!--#4DENDIF-->.

The word "any" is highlighted because a 4D function, a method that returns a value in $0, is a valid 4D expression with the 4DIF tag. When a 4D function is used as the expression with the tags 4DIF or 4DELSEIF and there is an error within the function, debugging becomes a challenge because the debugger will not break into the function when a TRACE or Breakpoint is set.

Take for example <!--#4DIF My4DFunction--> do something <!--#4DENDIF-->. In this scenario if there is an error within My4DFunction the debugger will not break into My4DFunction and the error will have to be found outside the context of when it was called by 4DIF.

The solution is to use 4D tags that support breaking in with the debugger during execution, 4DEVAL and 4DSCRIPT.

With 4DEVAL the condition test could be rewritten as follows:
<!--#4DEVAL $MyBool_B:=My4DFunction--><!--#4DIF $MyBool_B--> do something <!--#4DENDIF-->.

With 4DSCRIPT a process boolean variable will have to be set since it can only return TEXT in $0. It would be written as follows:
<!--#4DSCRIPT My4DFunction--><!--#4DIF MyBool_B--> do something <!--#4DENDIF-->