The function VarType tests a variant to determine what data type its value is.

For more information about variant data types including the current list of available data types, please review TVarType.

This is more commonly used with variant type variables, rather than fields - when accessing fields you can achieve the same thing by using the Field.FieldType property as illustrated below.

Declaration: Function VarType(const V : Variant) : TVarType;

An example.

procedure OnMapEvent(var Value:Variant);
begin
if VarType(Field.Value) = varOleStr then
Value := Field.Value;
end;

The function can also be used to good effect the following way to return the data type value.

procedure ScriptEvent (var Value : variant);
var
Str1 : string;
Var1, Var2 : variant;
WStr1 : widestring;
Bool1 : boolean;
begin
LogInfo('');
Str1 := 'Morning!';
LogInfo(Str1);
//Returns data type 258
LogInfo('Data type for STRING variable with TEXT = '+IntToStr(VarType(Str1)));
LogInfo('');
 
Var1 := 'Hello there βÆ£€èç';
LogInfo(Var1);
//Returns data type 256
LogInfo('Data type for VARIANT variable with TEXT = '+IntToStr(VarType(aVar)));
LogInfo('');
 
WStr1 := 'βÆ£€èç is a widestring';
LogInfo(WStr1);
//Returns VarType of 8
LogInfo('Data Type for WIDESTRING variable = '+IntToStr(VarType(WStr1)));
LogInfo('');
 
Var2 := null;
//Returns data type 1
LogInfo('Data type for null VARIANT = '+IntToStr(VarType(aVar)));
LogInfo('');
 
Bool1 := VarIsNull(Var2);
LogInfo(BoolToStr(Bool1, true));
//Returns data type 11
LogInfo('Data type for BOOLEAN = '+IntToStr(VarType(Bool1)));
LogInfo('');
 
end;