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-boun...@lists.freepascal.org > [mailto:fpc-pascal-boun...@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 > <m...@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@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal