Name
VarArrayLock Function
Syntax
function VarArrayLock(var V: Variant): Pointer;
Description
VarArrayLock locks the Variant
array’s dimensions so it cannot be resized, and returns a
pointer to a simple array of the Variant
array’s contents. The data array is organized such that the
leftmost index varies first (row-major order). Note that ordinary
Pascal arrays are stored in column-major order, so the rightmost
index varies first.
VarArrayLock is a real function.
Tips and Tricks
If you need to perform an operation on all the elements of the
Variantarray, lock the array first to enhance performance.The data array contains the actual values of each element of the
Variantarray. Verify that the array element type is what you expect, and cast the data pointer to the correct data type.While an array is locked, you cannot change its size, but you can change its contents. Changes to the array elements are reflected in the raw data array that
VarArrayLockreturns.You can lock an array more than once. To unlock the array, you must call
VarArrayUnlockonce for every time you callVarArrayLock.
Example
// Swap two doubles. procedure DSwap(var A, B: Double); var Tmp: Double; begin Tmp := A; A := B; B := Tmp; end; // Transpose a 2D matrix of varDouble values. For maximum performance, // lock the Variant array and access the raw data. procedure Transpose(var M: Variant); type TDoubleArray = array[0..MaxInt div SizeOf(Double)-1] of Double; PDoubleArray = ^TDoubleArray; var I, J: Integer; Data: PDoubleArray; ...
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