System.TVarRec

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

TVarRec = record { do not pack this record; it is compiler-generated }

C++

struct TVarRec
{
  union
  {
    int          VInteger;
    bool         VBoolean;
    AnsiChar     VChar;
    long double* VExtended;
    PShortString VString;
    void*        VPointer;
    PAnsiChar    VPChar;
#if !defined(DELPHI_AUTOREFCOUNT)
    TObject*     VObject;
#else
    void*        VObject;
#endif
    TClass       VClass;
    WideChar     VWideChar;
    WideChar*    VPWideChar;
    void*        VAnsiString;
    Currency*    VCurrency;
    Variant*     VVariant;
    void*        VInterface;
    void*        VWideString;
    __int64*     VInt64;
    void*        VUnicodeString;
  };
  union
  {
    Byte VType;
  };
  __fastcall TVarRec(): VType(vtInteger), VInteger(0) {} //default int 0
  __fastcall TVarRec(int src): VType(vtInteger), VInteger(src) {}
  __fastcall TVarRec(unsigned src): VType(vtInteger), VInteger(src) {}
  __fastcall TVarRec(unsigned long src): VType(vtInteger), VInteger(src) {}
  __fastcall TVarRec(long src): VType(vtInteger), VInteger(src) {}
  __fastcall TVarRec(bool src): VType(vtBoolean), VBoolean(src) {}
  __fastcall TVarRec(char src): VType(vtChar), VChar(src) {}
#if defined(_WIN64)
  __fastcall TVarRec(const double& src): VType(vtExtended), VExtended(reinterpret_cast<Extended*>(const_cast<double*>(&src))) {}
#endif
  __fastcall TVarRec(const long double& src): VType(vtExtended), VExtended(const_cast<Extended*>(&src)) {}
  __fastcall TVarRec(const ShortString& src): VType(vtString), VString(const_cast<PShortString>(&src)) {}
  __fastcall TVarRec(const void* src): VType(vtPointer), VPointer(const_cast<Pointer>(src)) {}
#if !defined(_DELPHI_STRING_UNICODE)
  __fastcall TVarRec(const PChar src): VType(vtPChar), VPChar(src) {}
#endif
  __fastcall TVarRec(const char* src): VType(vtPChar), VPChar(reinterpret_cast<PAnsiChar>(const_cast<char*>(src))) {}
#if !defined(DELPHI_AUTOREFCOUNT)
  __fastcall TVarRec(const TObject& src): VType(vtObject), VObject(const_cast<TObject*>(&src)) {}
#endif
  __fastcall TVarRec(const TClass src): VType(vtClass), VClass(src) {}
  __fastcall TVarRec(const WideChar* src): VType(vtPWideChar), VPWideChar(const_cast<PWideChar>(src)) {}
  __fastcall TVarRec(WideChar src): VType(vtWideChar), VWideChar(src) {}
#if !defined(_DELPHI_NEXTGEN)
  __fastcall TVarRec(const AnsiString& src): VType(vtAnsiString), VAnsiString(const_cast<void*>(src.data())) {}
  __fastcall TVarRec(const RawByteString& src): VType(vtAnsiString), VAnsiString(const_cast<void*>(src.data())) {}
#endif
  __fastcall TVarRec(const Currency& src): VType(vtCurrency), VCurrency(const_cast<PCurrency>(&src)) {}
  __fastcall TVarRec(const Variant& src): VType(vtVariant), VVariant(const_cast<PVariant>(&src)) {}
#if !defined(_DELPHI_NEXTGEN)
  __fastcall TVarRec(const WideString& src): VType(vtWideString), VWideString(const_cast<WideString&>(src).data()) {}
#endif
  __fastcall TVarRec(const UnicodeString& src): VType(vtUnicodeString), VUnicodeString(const_cast<void*>(src.data())) {}
  __fastcall TVarRec(const __int64& src): VType(vtInt64), VInt64(const_cast<PInt64>(&src)) {}
  __fastcall TVarRec(const unsigned __int64& src): VType(vtInt64), VInt64(reinterpret_cast<PInt64>(const_cast<PUInt64>(&src))) {}
  TVarRec& __fastcall operator =(int src)
  {
    VType = vtInteger;
    VInteger = src;
    return *this;
  }
  TVarRec& __fastcall operator =(unsigned src)
  {
    VType = vtInteger;
    VInteger = src;
    return *this;
  }
  TVarRec& __fastcall operator =(long src)
  {
    VType = vtInteger;
    VInteger = src;
    return *this;
  }
  TVarRec& __fastcall operator =(unsigned long src)
  {
    VType = vtInteger;
    VInteger = src;
    return *this;
  }
  TVarRec& __fastcall operator =(const __int64& src)
  {
    VType = vtInt64;
    VInt64 = const_cast<PInt64>(&src);
    return *this;
  }
  TVarRec& __fastcall operator =(const unsigned __int64& src)
  {
    VType = vtInt64;
    VInt64 = reinterpret_cast<PInt64>(const_cast<PUInt64>(&src));
    return *this;
  }
  TVarRec& __fastcall operator =(bool src)
  {
    VType = vtBoolean;
    VBoolean = src;
    return *this;
  }
  TVarRec& __fastcall operator =(char src)
  {
    VType = vtChar;
    VChar = src;
    return *this;
  }
  TVarRec& __fastcall operator =(const long double& src)
  {
    VType = vtExtended;
    VExtended = const_cast<PExtended>(&src);
    return *this;
  }
  TVarRec& __fastcall operator =(const ShortString& src)
  {
    VType = vtString;
    VString = const_cast<PShortString>(&src);
    return *this;
  }
  TVarRec& __fastcall operator =(const void* src)
  {
    VType = vtPointer;
    VPointer = const_cast<Pointer>(src);
    return *this;
  }
#if !defined(_DELPHI_STRING_UNICODE)
  TVarRec& __fastcall operator =(const PChar src)
  {
    VType = vtPChar;
    VPChar = src;
    return *this;
  }
#endif
  TVarRec& __fastcall operator =(const char* src)
  {
    VType = vtPChar;
    VPChar = static_cast<PAnsiChar>(const_cast<char*>(src));
    return *this;
  }
#if !defined(DELPHI_AUTOREFCOUNT)
  TVarRec& __fastcall operator =(const TObject& src)
  {
    VType = vtObject;
    VObject = const_cast<TObject*>(&src);
    return *this;
  }
#endif
  TVarRec& __fastcall operator =(const TClass& src)
  {
    VType = vtClass;
    VClass = src;
    return *this;
  }
  TVarRec& __fastcall operator =(WideChar src)
  {
    VType = vtWideChar;
    VWideChar = src;
    return *this;
  }
  TVarRec& __fastcall operator =(const WideChar* src)
  {
    VType = vtPWideChar;
    VPWideChar = const_cast<PWideChar>(src);
    return *this;
  }
#if !defined(_DELPHI_NEXTGEN)
  TVarRec& __fastcall operator =(const AnsiString& src)
  {
    VType = vtAnsiString;
    VAnsiString = const_cast<void*>(src.data());
    return *this;
  }
  TVarRec& __fastcall operator =(const WideString& src)
  {
    VType = vtWideString;
    VWideString = const_cast<WideString&>(src).data();
    return *this;
  }
#endif
  TVarRec& __fastcall operator =(const UnicodeString& src)
  {
    VType = vtUnicodeString;
    VUnicodeString = const_cast<void*>(src.data());
    return *this;
  }
  TVarRec& __fastcall operator =(const Currency& src)
  {
    VType = vtCurrency;
    VCurrency = const_cast<PCurrency>(&src);
    return *this;
  }
  TVarRec& __fastcall operator =(const Variant& src)
  {
    VType = vtVariant;
    VVariant = const_cast<PVariant>(&src);
    return *this;
  }
};

Properties

Type Visibility Source Unit Parent
record
struct
public
System.pas
systvar.h
System System

Description

TVarRec is used inside a function with an untyped array parameter.

The TVarRec type is used inside a function with a parameter type of array of const in Delphi. In Delphi, the compiler automatically translates each element in the array to a TVarRec value. In C++, the function parameter appears as an array of TVarRec values.

Use TVarRec to work with individual elements of the array when implementing the function that has an array of const parameter.

The VType field indicates the simple type of each TVarRec value. The variable type constants represent the values passed in the tag of the TVarRec structure. These constants, listed below, are defined in the System unit.

Delphi constants :



vtInteger

= 0;

vtBoolean

= 1;

vtCharacter

= 2;

vtExtended

= 3;

vtString

= 4;

vtPointer

= 5;

vtPChar

= 6;

vtObject

= 7;

vtClass

= 8;

vtWideChar

= 9;

vtPWideChar

= 10;

vtAnsiString

= 11;

vtCurrency

= 12;

vtVariant

= 13;

vtInterface

= 14;

vtWideString

= 15;

vtInt64

= 16;



C++ constants :



static const Shortint vtInteger

= 0x0;

static const Shortint vtBoolean

= 0x1;

static const Shortint vtCharacter

= 0x2;

static const Shortint vtExtended

= 0x3;

static const Shortint vtString

= 0x4;

static const Shortint vtPointer

= 0x5;

static const Shortint vtPChar

= 0x6;

static const Shortint vtObject

= 0x7;

static const Shortint vtClass

= 0x8;

static const Shortint vtWideChar

= 0x9;

static const Shortint vtPWideChar

= 0xa;

static const Shortint vtAnsiString

= 0xb;

static const Shortint vtCurrency

= 0xc;

static const Shortint vtVariant

= 0xd;

static const Shortint vtInterface

= 0xe;

static const Shortint vtWideString

= 0xf;

static const Shortint vtInt64

= 0x10;



Note: In C++, you can create an array of TVarRec values using the ARRAYOFCONST macro, which is defined in sysopen.h.