[Lazarus] EXC_BAD_ACCESS, Could not access memory

Hans-Peter Diettrich DrDiettrich1 at aol.com
Fri Apr 24 19:56:50 CEST 2009

Roland Turcan schrieb:

> BB> How is HeaderLen declared ?
> Stream.Read (HeaderLen, SIZEOF (HeaderLen));
> where information header's length is stored into binary.

The you should verify that HeaderLen <= SizeOf(FHeader), before
   Stream.Read (FHeader, HeaderLen);

Otherwise this statement will overwrite the following FItem data, with 
the fatal consequences you already experienced.

When a header will ever change in size (or structure), it's wise to 
store a version number in the data files. Then you can read the stored 
header data into the exactly applicable header type (record), and 
convert that record into the current THeader definition, field by field.


More information about the Lazarus mailing list