KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using Variant Inputs to Make Adaptable Methods
PRODUCT: 4D | VERSION: 18 | PLATFORM: Mac & Win
Published On: August 5, 2021

The Variant variable is a useful feature to implement more adaptable methods to a 4D database. For example some 4D commands can take in multiple types of inputs for a specific parameter.
The commands from the Object family of commands, which deal with the form objects, will target an object based on the passed object's name or Variable assigned to the object.

Before it would be difficult to replicate a similarly used Method, however using the Variant type, the a paramter can be a string or a pointer. Below is an example of a method that will have the first parameter be a variant with multiple optional text variables:

C_VARIANT($1)
C_TEXT({$2})

Conditional statements should then be used to prevent any errors and confirm the type of the inputs to the method.