Hi,
I am experimenting with static and dynamic arrays, reading bytes from a file.
The above code reads a number of bytes stored in Buffer1, a CRC check is then performed on those bytes (crc code etc has been omitted). This code works but has the limitation of only holding 342 bytes so I want to use a dynamic array so that the size of data processed can be changed during runtime, here is the new code which does not work - I receive an Access violation every time...
I've allocated the space prior to reading/processing so I don't see what the problem can be?
Thanks for any help
I am experimenting with static and dynamic arrays, reading bytes from a file.
Code:
var
Buffer1: array[0..341] of Byte;
begin
...
ReadCount := SourceFile.Read(Buffer1, SizeOf(Buffer1));
for k := 0 to ReadCount-1 do
TempResult := ((TempResult shr 8) and $FFFFFF) xor ValueTable[(TempResult xor Longword(Buffer1[k])) and $FF];
...
end;
The above code reads a number of bytes stored in Buffer1, a CRC check is then performed on those bytes (crc code etc has been omitted). This code works but has the limitation of only holding 342 bytes so I want to use a dynamic array so that the size of data processed can be changed during runtime, here is the new code which does not work - I receive an Access violation every time...
Code:
var
Buffer2: array of Byte;
Buffersize : integer;
begin
...
Buffersize := 342;
SetLength(Buffer2, Buffersize);
ReadCount := SourceFile.Read(Buffer2, SizeOf(Buffer2));
for k := 0 to ReadCount-1 do
TempResult := ((TempResult shr 8) and $FFFFFF) xor ValueTable[(TempResult xor Longword(Buffer2[k])) and $FF];
...
end;
I've allocated the space prior to reading/processing so I don't see what the problem can be?
Thanks for any help