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.
| Category | Constants | Key boundary |
|---|---|---|
| Empty/missing/error | varEmpty, varNull, varError | Unassigned, explicit Null and HRESULT/optional-argument error are three different states. |
| Signed integers | varShortInt, varSmallInt, varInteger, varInt64 | 8-, 16-, 32- and 64-bit storage; a script LongInt cannot hold every varInt64 value. |
| Unsigned integers | varByte, varWord, varLongWord | 8-, 16- and 32-bit storage; varLongWord is the legacy Delphi name for the unsigned 32-bit code. |
| Decimal/date/floating | varCurrency, varDate, varSingle, varDouble | Currency has exact four-decimal scaling; date is an Automation day count; binary floats have rounding, NaN and infinity behavior. |
| Strings | varOleStr, varString, varUString, varStrArg | BSTR is Automation-safe; managed RawByteString/UnicodeString codes are Delphi-specific; varStrArg is historical code 72, not an ordinary string type. |
| Interfaces | varDispatch, varUnknown | Reference-counted interfaces; dispatch access can execute external code and IUnknown does not guarantee late binding. |
| Nested/host representations | varVariant, varAny | Nested Variant/by-reference storage and Delphi's host-managed CORBA Any representation. |
| Modifiers and mask | varArray, varByRef, varTypeMask | Array 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.
varDateandvarDoubleuse the same physical floating width but have different semantic conversion rules.- Delphi-managed
varStringandvarUStringare not portable OLE Automation types. Cross-process/COM APIs generally require Automation-compatible types such asvarOleStr. varByRefpoints 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;
varDispatchmember 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