[Lazarus] Use of Move()?

Bo Berglund bo.berglund at gmail.com
Tue Feb 1 21:03:20 CET 2011


I think I have made an error.....
I have created a generalized buffer handler for my project and here I
have this function to read data from the buffer.

function TSSCommBuf.Read(Dest: Pointer; Count: Cardinal): Cardinal;
var
  num: Cardinal;
begin
  num := FWriteIndex - FReadIndex;  //Remaining data bytes in buffer
  if num >= Count then
    num := Count;
  if num > 0 then
  begin
    Move(FBuf[FReadIndex], Dest, num);
    FReadIndex := FReadIndex + num;
  end;
  Result := num;
end;

FWriteIndex is the next location in the byte array to write to and
FReadIndex is the next location to read from.
FBuf is a dynamic array of byte declared as:
type
  TByteArr = array of byte;
FBuf: TByteArr;

What happens here is that when I call the function to retrieve a byte
as follows it returns incorrect data.

function TSSCommBuf.Read(var Data: byte): boolean;
begin
  Result := Read(@Data, SizeOf(Data)) = SizeOf(Data);
end;

What I suspect is that I am not using the correct syntax for the Move
call.
I think I have read that there are subtle differences in FPC versus
Delphi concerning such things as addresses.....


Bo Berglund





More information about the Lazarus mailing list