procedure TPassOther.GetArray(var VData: OleVariant);
var
IntArray: array[1..10] of Integer;
I: Integer;
PData: PByteArray;
begin
{Put some numbers in the array.}
for I := 1 to 10 do IntArray[I] := I;
{Create the variant array of bytes. Set the upper bound to the size
of the array minus one because the array is zero based.}
VData := VarArrayCreate([0, SizeOf(IntArray) - 1], varByte);
{Lock the variant array for faster access then copy the array to the
variant array and unlock the variant array.}
PData := VarArrayLock(Vdata);
try
Move(IntArray, PData^, SizeOf(IntArray));
finally
VarArrayUnlock(VData);
end; //try
end;
procedure TMainForm.CopyArrayBtnClick(Sender: TObject);
var
IntArray: array[1..10] of Integer;
VData: Variant;
PData: PByteArray;
I: Integer;
begin
{Connect to the server application.}
if not MainDm.Conn.Connected then
MainDm.Conn.Open;
{Call the server's GetArray method and pass a variant parameter.}
MainDm.Conn.AppServer.GetArray(VData);
{Lock the variant array, copy the data to the array and
unlock the variant array.}
PData := VarArrayLock(VData);
try
Move(PData^, IntArray, SizeOf(IntArray));
finally
VarArrayUnlock(VData);
end; //try
{Display the array values in the memo.}
for I := 1 to 10 do
ArrayMemo.Lines.Add(IntToStr(IntArray[I]));
end;