[Lazarus] EXC_BAD_ACCESS, Could not access memory

Burkhard Carstens fpc at bcsoft.de
Fri Apr 24 15:27:30 CEST 2009

Am Freitag, 24. April 2009 15:11 schrieb dmitry boyarintsev:
> > Hm?
> TYPE TSomethingArr = ARRAY OF TSomeItem;
> declares a dynamic arrays. Dynamic arrays are implicit pointers, so
> should be used carefully in streaming operations.
> this should fix your problem:
> FUNCTION TMyObject.LoadFromStream (Stream:TStream):BOOLEAN;
> ...
>  SetLength (FItems, 0);
>  // make sure, that length of (FHeader) is greater than zero,
>  // otherwise it will cause another exception
>  Stream.Read (FHeader[0], HeaderLen);
>  SetLength (FItems, 0);
> END;

No, FHeader is just a record and not an array. IMO the provided code 
should work, assuming 
a) HeaderLen <= sizeof(TSomeHeader)
b) stream is a correctly initialized stream object
c) myObject is initialized correctly.

However, just a few more lines to make a complete and compilable example 
that shows the error would be nice ... 


More information about the Lazarus mailing list