Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-02

Incompatibility: dynamic array and TStream

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Donald Ziesig

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

Reply by email

Dmitry Boyarintsev
to Donald Ziesig
Donald Ziesig wrote 5 lines
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. Only one line is wrong, do the following:
Stream.Read(Buf[0], Stream.Size);

thanks,
Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160223/2b7d423d/attachment.html>

Reply by email

Donald Ziesig
to Dmitry Boyarintsev
Dmitry Boyarintsev wrote 22 lines
On Tue, Feb 23, 2016 at 9:39 PM, Donald Ziesig < <mailto:>> wrote: 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. Only one line is wrong, do the following: Stream.Read(Buf[0], Stream.Size); thanks, Dmitry -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Thanks, Dmitry. I'll try that tomorrow morning. It's getting late and I've been working for 14 hours so far. ;-)

I'll let you know then.

Thanks,

Don
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160223/e5d247d2/attachment-0001.html>

Reply by email