[fpc-pascal] Re: Array of byte from a COM object

Marcos Douglas md at delfire.net
Thu Jun 9 17:21:18 CEST 2011


On Thu, Jun 9, 2011 at 11:26 AM, Marcos Douglas <md at delfire.net> wrote:
>
> Hi,
> How I can a return "array of byte" from a COM object and put in a Stream?
> I use a OleVariant variable to get the return. But I can not convert
> in a string (the return is a XML).

I did using this function:

procedure VariantToStream(const V: OleVariant; const Stream: TStream);
var
  P: Pointer;
  L: Integer;
begin
  Assert(VarType(V) = varByte or varArray);
  Assert(VarArrayDimCount(V) = 1);

  L := VarArrayHighBound(V, 1) - VarArrayLowBound(V, 1) + 1;
  Stream.Size := L;
  Stream.Position := 0;

  P := VarArrayLock(V);
  try
    Stream.Write(P^, Stream.Size);
  finally
    VarArrayUnlock(V);
  end;
end;

Marcos Douglas



More information about the fpc-pascal mailing list