[fpc-pascal] Re: Array of byte from a COM object
Ludo Brands
ludo.brands at free.fr
Thu Jun 9 19:20:08 CEST 2011
If the Assert(VarType(V) = varByte or varArray); is not raising an error
then you are not getting a Safearray. VarArrayLock is for safearrays. If you
are getting an array of byte, you should be able to access the bytes as
V[i].
Do you have the interface definition for the method returning the "array of
byte"?
Ludo
> -----Message d'origine-----
> De : fpc-pascal-bounces at lists.freepascal.org
> [mailto:fpc-pascal-bounces at lists.freepascal.org] De la part
> de Marcos Douglas
> Envoyé : jeudi 9 juin 2011 17:21
> À : FPC-Pascal users discussions
> Objet : [fpc-pascal] Re: Array of byte from a COM object
>
>
> 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
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
More information about the fpc-pascal
mailing list