Skip to main content
Version: Next

Type

Type ( fieldVar ) : Integer

ParameterTypeDescription
fieldVarField, Variablefield or variable to be tested
Function resultIntegerData type number

Description

The Type command returns a numeric value that indicates the type of field or variable you have passed in the fieldVar parameter.

4D provides the following predefined constants found in the Field and Variable Types theme:

ConstantTypeValue
Array 2DInteger13
Blob arrayInteger31
Boolean arrayInteger22
Date arrayInteger17
Integer arrayInteger15
Is alpha fieldInteger0
Is BLOBInteger30
Is BooleanInteger6
Is collectionInteger42
Is dateInteger4
Is integerInteger8
Is integer 64 bitsInteger25
Is longintInteger9
Is nullInteger255
Is objectInteger38
Is pictureInteger3
Is pointerInteger23
Is realInteger1
Is string varInteger24
Is subtableInteger7
Is textInteger2
Is timeInteger11
Is undefinedInteger5
Is variantInteger12
LongInt arrayInteger16
Object arrayInteger39
Picture arrayInteger19
Pointer arrayInteger20
Real arrayInteger14
String arrayInteger21
Text arrayInteger18
Time arrayInteger32

You can apply the Type function to fields, interprocess variables, process variables, local variables, and dereferenced pointers for these types of objects. You can apply Type to the parameters ($1, $2 ... ${...}) of a project method or to the result of a function ($0).

Notes:

  • You can not apply the Type function to scalar expressions such as object properties (emp.name) or collection elements (myColl[5]). To do this, you must use the Value type command.
  • In compiled mode, calling Type on a method parameter declared as variant does not return Is variant but the actual data type (same as calling Value type).

Example 1

The following project method empties some or all of the fields for the current record of the table whose a pointer is passed as parameter. It does this without deleting or changing the current record:

  // EMPTY RECORD Project Method
  // EMPTY RECORD ( Pointer {; Long } )
  // EMPTY RECORD ( -> [Table] { ; Type Flags } )
 
 var $1 : Pointer
 var $2;$vlTypeFlags : Integer
 
 If(Count parameters>=2)
    $vlTypeFlags:=$2
 Else
    $vlTypeFlags:=0xFFFFFFFF
 End if
 For($vlField;1;Last field number($1))
    $vpField:=Field(Table($1);$vlField)
    $vlFieldType:=Type($vpField->)
    If($vlTypeFlags ??$vlFieldType )
       Case of
          :(($vlFieldType=Is alpha field)|($vlFieldType=Is text))
             $vpField->:=""
          :(($vlFieldType=Is real)|($vlFieldType=Is integer)|($vlFieldType=Is longint))
             $vpField->:=0
          :($vlFieldType=Is date)
             $vpField->:=!00/00/00!
          :($vlFieldType=Is time)
             $vpField->:=?00:00:00?
          :($vlFieldType=Is Boolean)
             $vpField->:=False
          :($vlFieldType=Is picture)
             var $vgEmptyPicture : Picture
             $vpField->:=$vgEmptyPicture
          :($vlFieldType=Is subtable)
             Repeat
                ALL SUBRECORDS($vpField->)
                DELETE SUBRECORD($vpField->)
             Until(Records in subselection($vpField->)=0)
          :($vlFieldType=Is BLOB)
             SET BLOB SIZE($vpField->;0)
       End case
    End if
 End for

After this project method is implemented in your database, you can write:

  // Empty the whole current record of the table [Things To Do]
 EMPTY RECORD(->[Things To Do])
 
  // Empty Text, BLOB and Picture fields for the current record of the table [Things To Do]
 EMPTY RECORD(->[Things To Do];0?+Is text?+Is BLOB?+Is picture)
 
  // Empty the whole current record of the table [Things To Do] except Alphanumeric fields
 EMPTY RECORD(->[Things To Do];-1?-Is alpha field)

Example 2

In certain cases, for example when writing generic code, you may need to find out whether an array is a standard independent array or the “row” of a 2D array. In this case, you can use the following code:

 ptrmyArr:=->myArr{6} // Is myArr{6} the row of a 2D array?
 RESOLVE POINTER(ptrmyArr;varName;tableNum;fieldNum)
 If(varName#"")
    $ptr:=Get pointer(varName)
    $thetype:=Type($ptr->)
  // If myArr{6} is the row of a 2D array, $thetype equals 13
 End if

Example 3

See example for the APPEND DATA TO PASTEBOARD command.

See also

Is a variable
Undefined
Value type

Properties

Command number295
Thread safe