Parameter and Variable Type Checking

If you need to ensure that the value passed to a parameter or a variable has only a certain type, you can do so. Values that are not of the correct type will be cast if possible, otherwise set to Invalid.

To enforce type checking, include the required type as part of the declaration. For example:

<
SubmoduleWithTypeChecking
(
String1 Text;
String2 Text;
Short1 Short;
)
...

If this module is called with values as follows:

Main [
SubModuleWithTypeChecking("ABC", 123, "DEF", 456);

then String1 will be set to "ABC", String2 will be set to "123", Short1 will be Invalid and Short2 will be 456. The number 123 can be cast to text, but "DEF" cannot be cast to a short.

The compiler will accept the following value types for your declarations:

  • Status (ie boolean)
  • Short
  • Long
  • Double
  • Float (same as double, deprecated)
  • Text
  • Buffer (same as text, deprecated)
  • Object
  • Reference (has no effect, deprecated)

 

Object-type variables / parameters can be further narrowed-down to objects whose modules have a name within a specified set of names. For example:

MyAnalogTag Object<AnalogInput, AnalogStatus>;