Click or drag to resize

EnforceType Function (Usual, DWord)

X#
Make sure a variable is of a certain type.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION EnforceType(
	u AS USUAL,
	dwType AS DWORD
) AS VOID
Request Example View Source

Parameters

u
Type: Usual
The variable to check.
If u is NIL and is passed by reference, the EmptyUsual() of the data type specified by dwType is assigned to it.
If u is not passed by reference and is not of the data type specified by dwType, the error system aborts the program.
If u is passed by reference but is not of the data type specified by dwType, the error system is called up and the EmptyUsual() of the data type specified by dwType is assigned to u.
dwType
Type: DWord
The data type to enforce.

Return Value

Type: 
Remarks
Examples
This example uses EnforceType() to ensure all arguments are of the correct type:
X#
1FUNCTION CheckArgs(cName, nScore, dDate, nMoney)
2    EnforceType(@cName, STRING)
3    EnforceType(@nScore, SHORTINT)
4        // Assigns 0 if NIL
5    EnforceType(@dDate, DATE)
6    EnforceType(@nMoney, LONGINT)    // Assigns 0 if NIL
7    EnforceType(@nOne, SHORTINT)    // Assigns 0 if NIL
See Also