[Lazarus] Incompatibility: dynamic array and TStream

Donald Ziesig donald at ziesig.org
Wed Feb 24 03:39:13 CET 2016


Hi All:

I am trying to read the contents of a memory stream into a dynamic array 
of characters and the program keeps crashing when I try to free the 
dynamic array.

Really simple code:

   Buf : array of Char;
   Stream : TMemoryStream;
begin

// Initialize Stream here
   SetLength( Buf, Stream.Size );
// do nothing here
   SetLength( Buf, 0 ); // This works

   SetLength( Buf, Stream.Size );
   Stream.Read( Buf ); // or Stream.ReadBuffer( B, Stream.Size );
   SetLength( Buf, 0 ); // This crashes

end;

I've tried passing the Address of Buf, but the compiler doesn't like it.
Does anyone have any ideas how I can work around this?

Thanks,

Don Ziesig




More information about the Lazarus mailing list