KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Check parameter types with Copy parameters
PRODUCT: 4D | VERSION: 19 R | PLATFORM: Mac & Win
Published On: May 16, 2022

4D v19 R5 introduced a command called Copy parameters that gives access to all parameters passed in a method. Since Copy parameters returns a collection of the parameters, various collection methods can be applied to the parameters to perform certain tasks. For instance, Copy parameters can be used in conjunction with the .every() method to check if the parameters’ value types are uniform. This would be a useful check to perform before continuing with a task.

For example, a method receives multiple port numbers as parameters. In this method, all port numbers should be text value type (instead of integer). This check can be performed like below:

$ports_coll:=Copy parameters

If ($ports_coll.every("isText"))
   // Do something
Else
   // Catch error
End if

The “isText” test method:

$1.result:=Value type($1.value)=Is text

If one or more port numbers are mistakenly passed as integers, the above test will catch it.