Name
TVarRec Type
Syntax
type
TVarRec = record
case Byte of
vtInteger: (VInteger: Integer; VType: Byte);
vtBoolean: (VBoolean: Boolean);
vtChar: (VChar: Char);
vtExtended: (VExtended: PExtended);
vtString: (VString: PShortString);
vtPointer: (VPointer: Pointer);
vtPChar: (VPChar: PChar);
vtObject: (VObject: TObject);
vtClass: (VClass: TClass);
vtWideChar: (VWideChar: WideChar);
vtPWideChar: (VPWideChar: PWideChar);
vtAnsiString: (VAnsiString: Pointer);
vtCurrency: (VCurrency: PCurrency);
vtVariant: (VVariant: PVariant);
vtInterface: (VInterface: Pointer);
vtWideString: (VWideString: Pointer);
vtInt64: (VInt64: PInt64);
end;Description
A subroutine parameter of type array
of
const is actually an array
of TVarRec records. Delphi converts each open
array element to a TVarRec record, filling in the
VType member with the type code and the
appropriate member with the actual value.
Tips and Tricks
Delphi uses open arrays and
TVarRecvalues to implement subroutines that take a variable number of arguments, while preserving complete type safety.TVarRecandTVarDataare entirely unrelated. They look similar because they do similar things, but they are not interchangeable.TVarReccan handle more types than aVariant, but it cannot handle all Delphi types. In particular, arrays, records, and enumerations are not supported.
Example
// Compute the sum of an arbitrary number of values. function Sum(const Data: array of const): Double; var I: Integer; begin Result := 0.0; for I := Low(Data) to High(Data) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access