varByte
varByte = 17
Example
function IsByteValue(const Value: Variant): Boolean;
begin
Result := (VarType(Value) and varTypeMask) = varByte;
end;
Usage
varByte identifies an unsigned 8-bit Variant integer and the Automation-safe element type commonly used for binary byte arrays.
Additional Technical Info
varByte is the base TVarType code $0011 for an unsigned 8-bit integer in the range 0..255. It is also the preferred Automation element type for raw binary data when combined with varArray.
Delphi normally packs a newly created numeric Variant to the smallest applicable type while the process-global PackVarCreation setting is true. Consequently, a small positive value may report varByte, while the same numeric value produced by another cast/provider may report varInteger, varWord or another compatible tag. Test the exact code only when representation matters.
VarAsType with varByte performs a conversion. Negative values, values above 255, non-integral numbers and invalid text can round, reject or raise a Variant conversion/range/overflow exception according to the source operation; validate business input before narrowing.
For varArray or varByte, the flag identifies Automation byte-array storage, not a script TBytes. Bound allocations and indexes, and use the approved Variant-array access functions rather than assuming a raw pointer or zero-copy representation.
Type inspection performs no conversion or I/O. Mask before testing when flags may be present.
The example is source-reviewed only; no numeric cast or array allocation was executed.
External references
Created 2026-07-15