[Lazarus] Use of Move()?
Bo Berglund
bo.berglund at gmail.com
Tue Feb 1 23:11:54 CET 2011
On Tue, 1 Feb 2011 21:18:57 +0100, Burkhard Carstens <fpc at bcsoft.de>
wrote:
>Am Dienstag, 1. Februar 2011 21:03 schrieb Bo Berglund:
>> 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);
>
>didn't read further, but: try Dest^ ..
>(quick guess)
>
Did not work, but I am using Move() in a way that has worked for me
using Delphi for many years, so it may have to do with Delphi vs fpc
differences....
What I usually do is the following:
Move(Source, Dest, Count);
where normally Source is an array, for example a string and Dest is
for example a multi-byte variable:
Move(SrcArr[Index], DestVar, SizeOf(DestVar);
Delphi manages to deduce what to use correctly so that the source is
the address of the array element Index and destination is the address
of the variable.
But when using FPC this may not really happen and this is what I am
trying to find out how to solve.
Here is the function that actually stuffs data into the buffer array:
function TSSCommBuf.Write(Source: Pointer; Count: Cardinal): boolean;
begin
Result := false;
if (FBufSize - FWriteIndex) < Count then
ExpandBuffer(FWriteIndex - FBufSize + Count);
Move(Source, FBuf[FWriteIndex], Count);
FWriteIndex := FWriteIndex + Count;
Result := true;
end;
Do I need to put @ or ^ characters in any part of this to make the
Move function work correctly?
Bo Berglund
More information about the Lazarus
mailing list