CHECK TYPE
Check at runtime the specified type of a variable or function/procedure parameter

 

 

 

The checking the type of a variable or a function/procedure parameter is useful for a defensive programming (minimization of input errors)

 

 

CHECK TYPE [ SOFT ] <VarName1> AS <VarType1> [ , < VarName2> AS < VarType2> [, < VarNameN> AS < VarTypeN> ] ]

 

Where:

<VarName>   --> is the name of variable

<VarType>   --> is one of the following variable types:

-    ARRAY

-    BLOCK

-    CHARACTER

-    DATE

-    HASH

-    LOGICAL

-    NIL

-    NUMERIC

-    MEMO

-    POINTER

-    SYMBOL

-    TIMESTAMP

-    OBJECT

-    USUAL (the variable can take any of the above types, in the practice the variable type is not checked)

 

SOFT --> when the SOFT clause is specified the variable can take the NIL value or the specified value, otherwise the variable can take only the value specified

 

 

 

Example:

 

Procedure MyDisplay( cName, nAge, aColor, xValue )

LOCAL Today := DATE()

 

   CHECK TYPE  cName    AS  CHARACTER   ,;

               nAge     AS  NUMERIC     ,;

               aColor   AS  ARRAY       ,;

               xValue   AS  USUAL       ,;

               Today    AS  DATE

   ...

Return   

 

 

 

Note: If any of the variables do not have the specified type an error message is displayed and the program is aborted.