Skip to main content

TVarType

TVarType = Word

Example

procedure ReadVariantType(Value: Variant; var TypeCode: TVarType);
begin
TypeCode := VarType(Value);
end;

Usage

TVarType stores the raw 16-bit Variant base code and representation flags returned by VarType.

Additional Technical Info

TVarType is an unsigned 16-bit Word used for a Variant's physical type metadata. VarType returns the raw top-level TVarData.VType field without conversion, masking or dereferencing.

It is not a closed enumeration. The low 12 bits hold a built-in or custom base number; higher bits can describe representation:

Code := VarType(Value);
Base := Code and varTypeMask;
IsArray := (Code and varArray) <> 0;
IsByRef := (Code and varByRef) <> 0;
RoleRegistered members
Empty/missingvarEmpty, varNull
Signed integersvarShortInt, varSmallInt, varInteger, varInt64
Unsigned integersvarByte, varWord, varLongWord
Floating/fixed/datevarSingle, varDouble, varCurrency, varDate
StringsvarOleStr, varString, varUString, internal varStrArg
Interfaces/statusvarDispatch, varUnknown, varError
Nested/specialvarVariant, host-managed varAny
Mask/flagsvarTypeMask, varArray, varByRef

Important implementation rules

  • Velox registers exactly the constants listed above. Current Delphi also defines varUInt32, varUInt64, varRecord, varObject, varUStrArg and custom-type ranges, but those names are not script-visible. varLongWord is the exposed legacy alias for current code 19/varUInt32.
  • varArray and varByRef are flags, not standalone base types. Mask for the base and test each flag separately. Array flags do not provide bounds, dimensions, locks or ownership.
  • A raw varByRef or varVariant wrapper can differ from its referent. Several Delphi predicates resolve that wrapper with FindVarData; VarType intentionally does not.
  • With Delphi's default PackVarCreation=True, equal numeric values can have different exact integer/floating tags according to their source and range. Use exact codes for representation decisions, not as the only business numeric test.
  • Pascal strings, arrays, interfaces and Any values have managed or borrowed lifetimes. A type code does not prove payload validity, safe retention, thread safety or absence of side effects.
  • varEmpty is uninitialised/cleared; varNull is explicitly missing. Converting either to a default value can erase that distinction.

Compare symbolic constants rather than hard-coded numbers. Do not persist a TVarType as a cross-language schema without a versioned contract.

The example is source-reviewed only; no Variant tag was read.

External references

Created 2026-07-15