[fpc-pascal] How to Copy a Record data to a buffer?

Matthias K. makadev at googlemail.com
Sat Oct 10 12:29:42 CEST 2009


Hi,
either use "Move( SendBuffer, rcvData, count )" (recommended since its
from rtl, not windows api) or
"CopyMemory( @rcvData[0], @SendBuffer, count )".
Its a common mistake to use @<dynamic array var> instead of @<dynamic
array var>[ 0 ].

regards

On Sat, Oct 10, 2009 at 11:51 AM, yu ping <spingyu at gmail.com> wrote:
> TCommsBuffer = packed record
>    UnitID: Byte;
>    FunctionCode: TModBusFunction;
>    MBPData: TModBusDataBuffer;
>    Spare: Byte;
>  end; { TCommsBuffer }
>
>
> SendBuffer: TCommsBuffer;
>
> --------------------------
> I want to send the data in SendBuffer to serial port
> I define a array type:
>
> rcvData:TDataByte;(TDataByte = array of byte)
> setlength(rcvData, sizeof(SendBuffer ) );
> count := datatosend;
> CopyMemory( @rcvData, @ SendBuffer , count);
> SeriComm.SendBuffer(@rcvData,count);
>
> when run to "CopyMemory( @rcvData, @ SendBuffer , count);" the program crash,
> what's wrong with me? Thanks.
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



More information about the fpc-pascal mailing list