Tech Tip: Generic parameters with New Formula command
PRODUCT: 4D | VERSION: 17 R3 | PLATFORM: Mac & Win
Published On: April 18, 2019
Typically, when seeing "$1, $2, ..." they are parameters within a method.
Here is an example when declared in a method:
C_TEXT($1) C_LONGINT($2) |
A developer has to keep in mind within the method of those parameter types otherwise errors may occur when not used properly. But for the New Formula command, the mechanism of the parameters can be easily set within the command without knowing the type which means it can be generic. There will not be any issues with checking syntax as well as compiling the code as 4D has already put in the hooks to allow the parameters to be any type.
Here is an example of setting a generic "addition" formula:
$obj:=New object("addition";New formula($1+$2)) |
This can parameters passed can be numeric or text as shown below without any type declaration within the New Formula command:
$number:=$obj.addition(1;2) // returns 3 $text:=$obj.addition("hello ";"world") // returns hello world |
See Also: