Tech Tip: Using PROCESS 4D TAGS and Local Variables
PRODUCT: 4D | VERSION: 14 R4 | PLATFORM: Mac & Win
Published On: July 8, 2015
Starting with 4Dv14R4, local variables in the calling context can no longer be accessed in the methods executed by PROCESS 4D TAGS, however local variables can be defined and used in by the methods executed by PROCESS 4D TAGS with the new 4DEVAL tag or accessed if passed as a parameter.
For example:
The first example method will not work as expected, because within the context of PROCESS 4D TAGS, $var_t is undeclared.
C_TEXT($var_t;$input_t;$output_t) $var_t:="Hello" $input_t:="<!--#4DTEXT $var_t-->" PROCESS 4D TAGS($input_t;$output_t) |
The method above will result in the following:
To use a local varible in the execution of a PROCESS 4D TAGS command the following two methods are available:
The following method declares and uses a local variable within the execution of the PROCESS 4D TAGS command which is valid. The variable is declared and used in the scope of the command using the new 4DEVAL tag introduced in v14R4. This is useful in cases where the variable is needed multiple times withing the script being processed by the PROCESS 4D TAGS command.
C_TEXT($input_t;$output_t) $input_t:="<!--#4DEVAL $var_t:=\"Hello\"--><!--#4DTEXT $var_t-->" PROCESS 4D TAGS($input_t;$output_t) |
The following method passes a local variable as a parameter into the PROCESS 4D TAGS command.
C_TEXT($var_t;$input_t;$output_t) $var_t:="Hello" $input_t:="<!--#4DTEXT $1-->" PROCESS 4D TAGS($input_t;$output_t;$var_t) |
Both of the above examples will result in the following: