TRecord=packed   record
        i:   Integer;
        s:   array [0..2] of string[200];
    end;
var
a:array of TRecord;
const
room = $AABBCC01;//命令头
begin
setlength(a,100);
//对a赋值
.
.
socket.sendbuf(...);//问题在这里...
end;我怎样将一个命令头+a一起发送出去?
我又怎样接收这个数据?然后判断命令的值等于$AABBCC01,那么就取出a数组?
江湖救急,希望兄弟姐妹们帮帮忙,实在因扰的不行了

解决方案 »

  1.   

    发两次,也可以创建一个空间.
    Sendbuf:pointer;
    CurrPoint:pointergetmem(sendbuf,4+sizeof(Trecord));
    CurrPoint :=SendBuf;
    move(room,CurrPoint,4);
    Currpoint :=pointer(longWord(CurrPoint)+4));
    move(a,CurrPoint,sizeof(TRecord);
    Sendbuf(Sendbuf,4+sizeof(Trecord));
    freemem(SendBuf);
      

  2.   

    建议发送 CommandHead + Length(A) + A
    type
    TRecord=packed   record 
            i:   Integer; 
            s:   array [0..2] of string[200]; 
        end; 
    ...type
      TPackHead = reocrd
        Command: LongWord;
        Length: Integer;
      end;
    var
      PackHead: TPackHead;
      a:array of TRecord; 
    const 
      room = $AABBCC01;//命令头 
    begin
      PackHead.LongWord := room;
      PackHead.Length := 100;
      SetLength(a, PackHead.Length);
      ...
      Socket.SendBuf(PackHead, sizeof(PackHead));
      Socket.SendBuf(A, sizeof(TRecord) * PackHead.Length);  SetLength(a, 0);
      A := Nil;
    end;
    接收:
    ...type
      TPackHead = reocrd
        Command: LongWord;
        Length: Integer;
      end;
    var
      PackHead: TPackHead;
      a:array of TRecord; 
    const 
      room = $AABBCC01;//命令头 
    begin
      Socket.RecvBuf(PackHead, sizeof(PackHead));
      if PackHead.Command <> room then Exit;  SetLength(a, PackHead.Length);
      ...  Socket.RecvBuf(A, sizeof(TRecord) * PackHead.Length);
      //处理
      ...
      
      SetLength(a, 0);
      A := Nil;
    end;
      

  3.   

    要特别注意如SendBuf/RecvBuf之类的各参数的参数类型。