我是用客户端发送一个数据结构
  IpHead=record
    sip:string;
    dip:string;
  end;
  ipbody=record
    content:string;
    end;
  ipgram=record
    head:IpHead;
    body:ipbody;
  end;var
   iptestc:ipgram; ClientSocket1.Socket.SendBuf(iptestc,sizeof(ipgram));//发送数据结构
server方应该如何接受
server方程序
 IpHead=record
      sip:string;
      dip:string;
    end;
    ipbody=record
      content:string;
      end;
    ipgram=record
      head:IpHead;
      body:ipbody;
    end;
var
  iptestc:ipgram;procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
beginSocket.ReceiveBuf(iptestc,sizeof(ipdram));
end;为什么接受不过来呢?

解决方案 »

  1.   

    IpHead=record
        sip:string;
        dip:string;
      end;
      ipbody=record
        content:string;
        end;
      ipgram=record
        head:IpHead;
        body:ipbody;
      end;String是可变的,实际是就是指针,大小就是4个字节,所以
    你要将String改为Char如:const
      MaxIPHeaderSize = 100;
      MaxIPCommentSize = 200;IpHead=record
        sip: array[0..MaxIPHeaderSize-1] of Char;
        dip:array[0..MaxIPHeaderSize-1] of Char;
      end;
    ...这样才可以,不信你可以用试试
    procedure TForm1.Button2Click(Sender: TObject);
    var
      S: string;
    begin
      S := '11111111111111111111111111111111111111';
      ShowMessage(IntToStr(Sizeof(s)));
    end;