[Lazarus] Why is setlength not allowed?

Michael Van Canneyt michael at freepascal.org
Sat Nov 16 11:50:45 CET 2019



On Sat, 16 Nov 2019, Bo Berglund via lazarus wrote:

> function InitI2cDevice(devpath: String; iDevAddr: Cint; var hInst:
> Integer): Integer;
> var
>  iio : integer;
> begin
>  try
>    hInst := fpopen(devpath, O_RDWR);                       //Open the
> I2C bus in Read/Write mode
>    iio := FpIOCtl(hInst, I2C_SLAVE, Pointer(iDevAddr));    //Set
> options
>    if (iio = 0) and (hInst > 0) then
>      Result := hInst
>    else
>      Result := -1;
>  except
>    Result := -1;
>  end;
> end;
>
> In this case I get a warning:
> rpii2ccomm.pas(80,38) Hint: Conversion between ordinals and pointers
> is not portable
>
> It is on the line:
> iio := FpIOCtl(hInst, I2C_SLAVE, Pointer(iDevAddr));
>
> I guess that the reason is that fpIoCtrl expects a pointer type
> variable so the typecast is done... Is there no alternative?

The warning seems correct. I suspect Pointer(iDevAddr) is probably wrong. 
Maybe  Pointer(@iDevAddr)) is needed. I would need to see the original code.

Michael.


More information about the lazarus mailing list