xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

Type()

Determines the data type of a macro expression.

Syntax

Type( <cMacroExpr> ) --> cDataType

Arguments

<cMacroExpr>
This is a character string holding the name of a dynamic memory variable (PRIVATE or PUBLIC), field variable or an expression.

Return

The function returns a character string identifying the data type of <cMacroExpr> when it is evaluated using the macro operator (&) (see description).

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 valueData type
AArray
BCode block
CCharacter string
DDate value
HHash
LLogical value
MMemo field
NNumeric value
OObject
PPointer to function or method
UUndefined symbol or NIL
UESyntax error in macro expression
UIData 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.

Info

See also:Valtype()
Category: Debug functions
Source:rtl\type.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe