Originale-mail to me for new edition

 

Variant arrays

 

You cannot assign an ordinary static array to a variant. Instead, create a variant array by calling either of the standard functions VarArrayCreate or VarArrayOf. For example,

V: Variant;

 ...

V := VarArrayCreate([0,9], varInteger);

creates a variant array of integers (of length 10) and assigns it to the variant V. The array can be indexed using V[0], V[1], and so forth, but it is not possible to pass a variant array element as a var parameter. Variant arrays are always indexed with integers.

The second parameter in the call to VarArrayCreate is the type code for the array’s base type. For a list of these codes, see VarType. Never pass the code varString to VarArrayCreate; to create a variant array of strings, use varOleStr.

Variants can hold variant arrays of different sizes, dimensions, and base types. The elements of a variant array can be of any type allowed in variants except ShortString and AnsiString, and if the base type of the array is Variant, its elements can even be heterogeneous. Use the VarArrayRedim function to resize a variant array. Other standard routines that operate on variant arrays include VarArrayDimCount, VarArrayLowBound, VarArrayHighBound, VarArrayRef, VarArrayLock, and VarArrayUnlock.

When a variant containing a variant array is assigned to another variant or passed as a value parameter, the entire array is copied. Don’t perform such operations unnecessarily, since they are memory-inefficient.

 

Topic groups

 

See also

Dynamic arrays

Static arrays

Variant types: Overview

 

 

译文

 

变体数组

 

不能将一般的静态数组赋值给变体。取代的途径是,用标准函数VarArrayCreateVarArrayOf创建一个变体数组(variant array)。例如,

V: Variant;

 ...

V := VarArrayCreate([0,9], varInteger);

这里创建了一个长度为10的整数变体数组,并将该变体数组赋值给变体V。这里的数组可以用V[0]V[1] 等索引,但不能将变体数组元素作为var参数传递。变体数组总是以整数来索引。

调用函数VarArrayCreate的第二个参数是数组基类型的类型代码。(类型代码列表见标准函数VarType)决不要传递类型代码varString到函数VarArrayCreate;要创建串变体数组,应使用varOleStr

变体可以保存不同尺寸、维数和基类型的变体数组。变体数组的元素可以是任何在变体中允许的类型(ShortStringAnsiString除外);如果变体数组的基类型是标准变体Variant,那么其元素甚至可以是不同种类的。使用标准函数VarArrayRedim可以重新设置变体数组的尺寸。其他作用于变体数组的标准例程包括VarArrayDimCountVarArrayLowBoundVarArrayHighBoundVarArrayRefVarArrayLockVarArrayUnlock

当一个包含了变体数组的变体被赋值给另一个变体或作为值参数被传递时,整个数组被复制。由于这样的操作将耗费大量的内存,因此,除非必要,否则不要执行此操作。

 

主题组

 

相关主题

动态数组

静态数组

变体类型:概述