KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Value type returns different results for integers as variant parameters
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: April 8, 2024

When working with project methods or class functions that have parameters declared as variant type, note that the command Value type, depending on the context, will return different results for integer values passed in as variant parameter. In interpreted mode, it will return 1 (Is real), and in compiled mode, it will return 9 (Is longint). For example, given the following method “myAlert”:

// myAlert
#DECLARE($param : Variant)

ALERT(String(Value type($param)))

When myAlert(40) is executed in interpreted mode, it will alert “1”. When the same is executed in compiled, it will alert “9”. If testing for value type in both scenarios, remember to check for either case. The Is compiled mode command can be used to confirm interpreted or compiled mode. Also, both cases can be covered with an OR statement, for example:

If (Value type($param)=Is real) | (Value type($param)=Is longint)
   // Do something
End if