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

yu ping spingyu at gmail.com
Sat Oct 10 11:51:59 CEST 2009


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.



More information about the fpc-pascal mailing list