Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə109/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   105   106   107   108   109   110   111   112   ...   294
DelphiLanguageGuide

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
.
Note:
Variant arrays of custom variants are not supported, as instances of custom variants can be added to a
VarVariant
 variant array.
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.
OleVariant
The OleVariant type exists on both the Windows and Linux platforms. The main difference between Variant and
OleVariant is that Variant can contain data types that only the current application knows what to do with. OleVariant
can only contain the data types defined as compatible with OLE Automation which means that the data types that
can be passed between programs or across the network without worrying about whether the other end will know
how to handle the data.
95


When you assign a Variant that contains custom data (such as a Delphi string, or a one of the new custom variant
types) to an OleVariant, the runtime library tries to convert the Variant into one of the OleVariant standard data types
(such as a Delphi string converts to an OLE BSTR string). For example, if a variant containing an AnsiString is
assigned to an OleVariant, the AnsiString becomes a WideString. The same is true when passing a Variant to an
OleVariant function parameter.
96



Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   105   106   107   108   109   110   111   112   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin