xHarbour Reference Documentation > Function Reference |
Determines the data type of a macro expression.
Type( <cMacroExpr> ) --> cDataType
The function returns a character string identifying the data type of <cMacroExpr> when it is evaluated using the macro operator (&) (see description).
Type() is used to determine the data type of a macro expression by evaluating or executing it with the macro operator. The expression is most often the name of a dynamic memory variable, or a field variable.
Type() can also determine the data type of a macro expression containing function calls. This is restricted, however, to basic functions built into xHarbour which operate on simple data types. If the macro expression contains calls to complex functions or user-defined functions, Type() does not evaluate the macro expression and, thus, cannot determine the data type.
The function returns one of the following characters or character strings
Return values of Type()
Return value | Data type |
---|---|
A | Array |
B | Code block |
C | Character string |
D | Date value |
H | Hash |
L | Logical value |
M | Memo field |
N | Numeric value |
O | Object |
P | Pointer to function or method |
U | Undefined symbol or NIL |
UE | Syntax error in macro expression |
UI | Data type is indeterminable (macro expression too complex) |
Note Type() cannot determine the data type of lexically scoped variables (GLOBAL, LOCAL and STATIC). Use Valtype() for such variables.
See also: | Valtype() |
Category: | Debug functions |
Source: | rtl\type.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// This example shows all possible return values of Type() PROCEDURE Main PRIVATE aArray := { 1, 2, 3 } PRIVATE bBlock := {|x| 1+x } PRIVATE cChar := "xHarbour" PRIVATE dDate := Date() PRIVATE hHash := Hash() PRIVATE lLogic := .F. PRIVATE nNumber := 123.45 PRIVATE oObject := GetNew() PRIVATE pPtr := ( @Test() ) PRIVATE uNIL := NIL USE Customer ALIAS Cust ? Type( "aArray" ) // result: A ? Type( "bBlock" ) // result: B ? Type( "cChar" ) // result: C ? Type( "dDate" ) // result: D ? Type( "hHash" ) // result: H ? Type( "lLogic" ) // result: L ? Type( "Cust->notes" ) // result: M ? Type( "nNumber" ) // result: N ? Type( "oObject" ) // result: O ? Type( "pPtr" ) // result: P ? Type( "uNIL" ) // result: U ? Type( "Val(" ) // result: UE ? Type( "Test()" ) // result: UI ? Type( "TestFunc()" ) // result: U ? Type( "Date()" ) // result: D ? Type( "oObject:hasFocus()" ) // result: L Test( pPtr, hHash ) // result: P H ? Type( "'A'" ) // result: C ? Type( "A" ) // result: U ? Type( "{1}" ) // result: A ? Type( "{=>}" ) // result: H ? Type( "9" ) // result: N ? Type( ".F." ) // result: L ? Type( "IIf(.T.,'A',1)" ) // result: C RETURN PROCEDURE Test PARAMETERS p1, p2 ? Type( "p1" ), Type( "p2" ) RETURN
http://www.xHarbour.com