//客户端
procedure TfrmClientTcpip.Button11Click(Sender: TObject);
Var
s : TMemoryStream;
o : OLEVariant;
p : Pointer;
v1,v2,v3,v4:OLEVariant;//4个字段
begin
If Not ADODataSet1.Eof Then
Begin
s := TMemoryStream.Create; //Stream
v1 := ADODataSet1.FieldByName('a').CurValue;//OleVariant
v2 := ADODataSet1.FieldByName('b').CurValue;//OleVariant
v3 := ADODataSet1.FieldByName('c').CurValue;//OleVariant
v4 := ADODataSet1.FieldByName('d').CurValue;//OleVariant
o := VarArrayOf([v1,v2,v3,v4]);
p := VarArrayLock(o); //Init p
s.Write(p^,VarArrayHighBound(o,1)+1); //Init s
csTcpip.Socket.SendBuf(p^,VarArrayHighBound(o,1)+1);
End;
end;
//服务器端:
procedure TfrmServerTcpip.ssTcpipClientRead(Sender: TObject;
Socket: TCustomWinSocket);
Var
o : OLEVariant;
p : Pointer;
v : OLEVariant;
begin
v := VarArrayOf(['a','b','c','d']);
o := VarArrayCreate([0, Socket.ReceiveLength - 1], varByte);
Try
Try
p := VarArrayLock(o);
Socket.ReceiveBuf(p^,Socket.ReceiveLength);
ADODataset1.Recordset.AddNew(v,o);
Finally
VarArrayUnlock(o);
End;
Except
Application.MessageBox(PChar('错误'),PChar('错误'),MB_OK+MB_ICONINFORMATION);
Abort();
End;
end;