有这样一个数据结构 DeliverResp *pDeliverResp
其中pDeliverResp结构如下
sMsgID Char(11)
nMsgFormat Int
sSrcrmID Char(22)
sDestTermID Char(22)
nIsReply Char(22)
nMsgLen Int
sMsgContent Char(252)
我是这样对应的
 msgp=  record
  sMsgID:array [0..11] of char ;
  nMsgFormat:integer;
  sRecvTime:array [0..16] of char ;
  sSrcrmID:array [0..22] of char ;
  sDestTermID:array [0..22] of char ;
  nIsReply:array [0..22] of char ;
  nMsgLen:integer;
  sMsgContent: array [0..252] of char ;
  end;
tpDeliverResp=^msgp;
为什么用的时候会出错?

解决方案 »

  1.   

    type
      msgp = packed record // packed改变对齐方式
        sMsgID: array [0..11 - 1] of Char; //0..11是12个元素,所以要-1
        nMsgFormat: Integer;
        sRecvTime: array [0..16 - 1] of Char;
        sSrcrmID: array [0..22 - 1] of Char;
        sDestTermID: array [0..22 - 1] of Char;
        nIsReply: array [0..22 - 1] of Char;
        nMsgLen: Integer;
        sMsgContent: array [0..252 - 1] of Char;
      end;
      

  2.   

    那在具体用的时候
    是用getmem(tpDeliverResp,sizeof(tpDeliverResp))
    还是用new(tpDeliverResp);
      

  3.   

    看实际需要:
    如果是多个数据,看成列表需要用
    GetMem(tpDeliverResp, SizeOf(tpDeliverResp) * Count)
    只是一个元素就用New(tpDeliverResp)
      

  4.   

    type pDeliverResp=^msgp;
    msgp=  record
      sMsgID:array [0..11] of char ;
      nMsgFormat:integer;
      sRecvTime:array [0..16] of char ;
      sSrcrmID:array [0..22] of char ;
      sDestTermID:array [0..22] of char ;
      nIsReply:array [0..22] of char ;
      nMsgLen:integer;
      sMsgContent: array [0..252] of char ;
      end;