Skip to main content

Variant Types

Available type codes

Velox exposes these 26 constants as Word values. They describe the raw representation returned by VarType; they do not convert a value merely by being compared or combined.

CategoryConstantsKey boundary
Empty/missing/errorvarEmpty, varNull, varErrorUnassigned, explicit Null and HRESULT/optional-argument error are three different states.
Signed integersvarShortInt, varSmallInt, varInteger, varInt648-, 16-, 32- and 64-bit storage; a script LongInt cannot hold every varInt64 value.
Unsigned integersvarByte, varWord, varLongWord8-, 16- and 32-bit storage; varLongWord is the legacy Delphi name for the unsigned 32-bit code.
Decimal/date/floatingvarCurrency, varDate, varSingle, varDoubleCurrency has exact four-decimal scaling; date is an Automation day count; binary floats have rounding, NaN and infinity behavior.
StringsvarOleStr, varString, varUString, varStrArgBSTR is Automation-safe; managed RawByteString/UnicodeString codes are Delphi-specific; varStrArg is historical code 72, not an ordinary string type.
InterfacesvarDispatch, varUnknownReference-counted interfaces; dispatch access can execute external code and IUnknown does not guarantee late binding.
Nested/host representationsvarVariant, varAnyNested Variant/by-reference storage and Delphi's host-managed CORBA Any representation.
Modifiers and maskvarArray, varByRef, varTypeMaskArray and indirect-reference bits modify a base type; mask them before testing the low 12-bit base code.

Correct inspection pattern

RawType := VarType(Value);
BaseType := RawType and varTypeMask;
IsArray := (RawType and varArray) <> 0;
IsByReference := (RawType and varByRef) <> 0;

Testing VarType(Value) = varByte rejects a byte array because its raw code also contains varArray. Conversely, masking first loses information about arrays and references, so retain the raw code when storage/lifetime matters.

Representation and conversion boundaries

  • A mathematical value does not identify one Variant tag. Packed creation and external Automation providers can choose narrower or different compatible representations.
  • varDate and varDouble use the same physical floating width but have different semantic conversion rules.
  • Delphi-managed varString and varUString are not portable OLE Automation types. Cross-process/COM APIs generally require Automation-compatible types such as varOleStr.
  • varByRef points at storage owned elsewhere. Its validity and mutability depend on the caller's lifetime; retaining or dereferencing it outside that contract is unsafe.
  • Variant arrays can have non-zero and multidimensional bounds. Inspect bounds rather than assuming a zero-based one-dimensional list.
  • Interface and managed-string Variants participate in reference counting. Assignment and clearing can execute lifetime management; varDispatch member access can invoke arbitrary provider code.
  • Raw codes are runtime representation details. Do not persist them as business type identifiers or use them in place of dataset TFieldType.

External references

Created 2026-07-15