Miscellaneous Datatypes
Datatypes miscellaneous
Contents |
What are the initial values of variables in TD 
All variables in TD are initially set to a specific value.
For instance, a local Number variable within a function is automatically initialized with value = 0 (zero).
Here the list of base datatypes and their initial values:
Binary | BINARY_Null |
Boolean | FALSE (0) |
DateTime | DATETIME_Null |
File Handle | hWndNULL |
Long String | STRING_Null ("") |
Number | 0 |
Session Handle | hWndNULL |
Sql Handle | hWndNULL |
String | STRING_Null ("") |
Window Handle | hWndNULL |
UDV | != OBJ_Null |
As for objects/UDV's (instances of functional classes):
An object and all it's attributes (class variables/Instance variables) are initialized using the table above.
Though, you can initialize an object to OBJ_Null (starting from CTD 2.0) by assigning OBJ_Null at the declaration:
♦ Variables cfcTest: uMyUDV = OBJ_Null
How to get dynamically the type of a variable 
At runtime, the function SalCompileAndEvaluate can be used to determine the type of a variable.
Set nType = SalCompileAndEvaluate( sExpression, nError, nErrorPos, nReturn, sReturn, dtReturn, hWndReturn, FALSE, sContext ) If nType = EVAL_Number ! Variable is a Number Else If nType = EVAL_String ! Variable is a String Else if ntype = EVAL_Date ! Variable is a DateTime Else If nType = EVAL_Handle ! Variable is a Handle (window, Sql, File) ELse If nType = EVAL_Template ! sExpression is a template, class Else If nType = 7 ! Variable is an object (UDV). This nType seems to be undocumented
Example
Set nType = SalCompileAndEvaluate( "strTest", nError, nErrorPos, nReturn, sReturn, dtReturn, hWndReturn, FALSE, sContext ) Set nType = SalCompileAndEvaluate( "udvCustomer", nError, nErrorPos, nReturn, sReturn, dtReturn, hWndReturn, FALSE, sContext )
The sContext parameter should be the context handle where the variable resides in.
So if the variable is declared in the current context (where the SalCompileAndEvaluate is called) use
sContext = SalContextCurrent( )