[Lazarus] Why is setlength not allowed?
Bo Berglund
bo.berglund at gmail.com
Sat Nov 16 08:48:43 CET 2019
I am trying to write a simple I2C interface program for Raspberry Pi
but I am getting an error I don't understand...
function TRaspiI2C.ReadI2CBytes(addr: integer; count: integer; buf:
array of byte): integer;
var
i: integer;
begin
try
if count <> length(buf) then
SetLength (buf, count); <== ERROR HERE!
for i := 0 to count -1 do
buf[i] := ReadI2CByte(addr + i);
Result := count;
except
Result := 0;
end;
end;
The error message states:
rpii2ccomm.pas(158,7) Error: Type mismatch
I have used setlength on dynamic byte arrays many times before and
never gotten this strange error message.
What am I doing wrong???
I have tried declaring buf as var in the call but it does not help.
(addr: integer; count: integer; var buf: array of byte): integer;
The same error happens.
Must be something basic I have missed.
Lazarus placed this at the top of the unit when I created it, if that
matters:
{$mode objfpc}{$H+}
Using FPC 3.0.4 and Lazarus 2.0.6 on Raspbian Buster
--
Bo Berglund
Developer in Sweden
More information about the lazarus
mailing list