Originale-mail to me for new edition

 

Variant types

 

A variant is stored as a 16-byte record that contains a type code and a value (or a reference to a value) of the type given by the code. The System and Variants units define constants and types for variants.

The TVarData type represents the internal structure of a Variant variable (on Windows, this is identical to the Variant type used by COM and the Win32 API). The TVarData type can be used in typecasts of Variant variables to access the internal structure of a variable.

The VType field of a TVarData record contains the type code of the variant in the lower twelve bits (the bits defined by the varTypeMask constant). In addition, the varArray bit may be set to indicate that the variant is an array, and the varByRef bit may be set to indicate that the variant contains a reference as opposed to a value.

The Reserved1, Reserved2, and Reserved3 fields of a TVarData record are unused.

The contents of the remaining eight bytes of a TVarData record depend on the VType field. If neither the varArray nor the varByRef bits are set, the variant contains a value of the given type.

If the varArray bit is set, the variant contains a pointer to a TVarArray structure that defines an array. The type of each array element is given by the varTypeMask bits in the VType field.

If the varByRef bit is set, the variant contains a reference to a value of the type given by the varTypeMask and varArray bits in the VType field.

The varString type code is private. Variants containing a varString value should never be passed to a non-Delphi function. On Windows, Delphi's Automation support automatically converts varString variants to varOleStr variants before passing them as parameters to external functions.

On Linux, VT_decimal is not supported.

 

Topic groups

 

See also

Memory management: Overview

Variables

Variant types: Overview

 

 

译文

 

变体类型

 

变体类型存储为16字节(128位)的记录,该记录包含了一个类型代码和一个类型与类型代码相匹配的值(或对值的引用)。System单元和Variants单元中为变体定义了常量和类型。

TVarData类型用于内部表示Variant变量的接口(在Windows中,等同于用于COMWin32 APIVariant类型)。TVarData类型可以被用于Variant变量的类型转换,以访问变量的内部结构。

TVarData记录中的VType字段在其最低的12个比特(这些位被定义为varTypeMask)中包含了变体的类型代码。此外,varArray位可以被设置用来表示变体是一个数组,varByRef位可以被设置用于表示变体包含了一个对值的引用。

TVarData记录中的Reserved1Reserved2Reserved3等字段未被使用。

TVarData记录中其余的8个字节,其内容取决于VType字段。如果varArray位和varByRef位都没有被设置,那么变体包含了给定类型的值。

如果varArray位被设置(值为1),那么变体包含了一个指针,该指针指向定义了一个数组的TVarArray结构。数组元素的类型由VType字段中的varTypeMask位给出。

如果varByRef位被设置(值为1),那么变体包含对一个值的引用,该值的类型由VType字段中的varTypeMask位和varArray位给出。

类型代码varString是私有的(编译器)。包含varString值的变体不应被传递到非Delphi函数。在Windows中,在将类型为varString的变体作为参数传递到外部函数之前,Delphi的自动化支持将会自动把varString类型的变体转换为varOleStr的变体。

Linux中,VT_decimal不支持。

 

主题组

 

相关主题

内存管理:概述

变量

变体类型:概述