SmartPascal
VarTypeMask
Constant
Mask for the meta-type part of a Variant variable Variants unit
  const VarTypeMask = $0FFF;
Description
The VarTypeMask constant provides a mask for use with the VarType function. It allows the meta-type part of a Variant to be excluded when checking for the basic data type of a Variant.
 
The data type is a 16 bit value, split into a high order 4 bits and a low order 12 bits. The high order bits give a meta data type:
 
varArray  : If the Variant holds an array of data
varByRef  : If the Variant indirectly refers to data

 
The low order bits contain one of the following values:
 
varEmpty
varNull
varSmallint
varInteger
varSingle
varDouble
varCurrency
varDate
varOleStr
varDispatch
varError
varBoolean
varVariant
varUnknown
varShortInt
varByte
varWord
varLongWord
varInt64
varStrArg
varString
varAny
Related commands
Variant A variable type that can hold changing data types
VarType Gives the current type of a Variant variable
 
Example code : Illustrating a few Variant types using VarTypeMask
var
  myVar : Variant;

begin
  // Assign various values to a Variant
  // and then show the resulting Variant type
  ShowMessage('Variant value = not yet set');
  ShowBasicVariantType(myVar);

  // Simple value
  myVar := 123;
  ShowMessage('Variant value = 123');
  ShowBasicVariantType(myVar);

  // Calculated value using a Variant and a constant
  myVar := myVar + 456;
  ShowMessage('Variant value = 123 + 456');
  ShowBasicVariantType(myVar);

  myVar := 'String '+IntToStr(myVar);
  ShowMessage('Variant value = String 579');
  ShowBasicVariantType(myVar);
end;

// Show the type of a variant
procedure TForm1.ShowBasicVariantType(varVar: Variant);
var
  typeString : string;
  basicType  : Integer;

begin
  // Get the Variant basic type :
  // this means excluding array or indirection modifiers
  basicType := VarType(varVar) and VarTypeMask;

  // Set a string to match the type
  case basicType of
    varEmpty     : typeString := 'varEmpty';
    varNull      : typeString := 'varNull';
    varSmallInt  : typeString := 'varSmallInt';
    varInteger   : typeString := 'varInteger';
    varSingle    : typeString := 'varSingle';
    varDouble    : typeString := 'varDouble';
    varCurrency  : typeString := 'varCurrency';
    varDate      : typeString := 'varDate';
    varOleStr    : typeString := 'varOleStr';
    varDispatch  : typeString := 'varDispatch';
    varError     : typeString := 'varError';
    varBoolean   : typeString := 'varBoolean';
    varVariant   : typeString := 'varVariant';
    varUnknown   : typeString := 'varUnknown';
    varByte      : typeString := 'varByte';
    varWord      : typeString := 'varWord';
    varLongWord  : typeString := 'varLongWord';
    varInt64     : typeString := 'varInt64';
    varStrArg    : typeString := 'varStrArg';
    varString    : typeString := 'varString';
    varAny       : typeString := 'varAny';
    varTypeMask  : typeString := 'varTypeMask';
  end;

  // Show the Variant type
  ShowMessage('Variant type is '+typeString);
end;
Show full unit code
   Variant value = not yet set
   Variant type  = varEmpty
   Variant value = 123
   Variant type  = varByte
   Variant value = 123 + 456
   Variant type  = varInt64
   Variant value = String 579
   Variant type  = varString