I have a WebService that returns a Variant me that it has an Array ie varArray, would like to know how to get the data that varArray.
Thanks for the help.
To get the content of a varArray you must use the VarArrayLowBound and VarArrayHighBound functions, then using a loop you can iterate over the array to get the data.
Try this sample
var
i : integer;
s : string;
begin
for i := VarArrayLowBound(vArray, 1) to VarArrayHighBound(vArray, 1) do
s:=vArray[i];//copy the the content of the array i element into a string
VarArrayAsPSafeArray allows direct access to the array and means you can avoid element-wise copying which gets very slowAssuming that the underlying data type is Byte, and that the array is 1-dimensional, the way I would solve this is as follows:
function GetBytesFromVariant(const V: Variant): TBytes;
var
Len: Integer;
SafeArray: PVarArray;
begin
Len := 1+VarArrayHighBound(vArray, 1)-VarArrayLowBound(vArray, 1);
SetLength(Result, Len);
SafeArray := VarArrayAsPSafeArray(V);
Move(SafeArray.Data^, Pointer(Result)^, Length(a)*SizeOf(a[0]));
end;
If the underlying element type is something else, e.g. Word, Integer etc., it should be obvious how to modify this to match.