Sending the right record size over socket
<p>I have this record:</p>

<pre><code>type
  TSocks5_Packet = record
    Socks_ID: String[6];
    Socks_Packet: array of byte;
  end;
</code></pre>

<p>I put String[6] because I'm sure that this string will always have 6 characters (and to try facilitate my job, but wasn't enough). </p>

<p>I try to send this record here:</p>

<pre><code>procedure TForm1.SocksServerClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
  Socks5_Request: TSocks5_Packet;
begin
  SetLength(Socks5_Request.Socks_Packet, Socket.ReceiveLength);
  Socket.ReceiveBuf(Socks5_Request.Socks_Packet[0], Length(Socks5_Request.Socks_Packet));
  Socks5_Request.Socks_ID:= PSocket_Identity(Socket.Data).Sock_ID;
  TunnelClient.SendBuf(Socks5_Request, Length(Socks5_Request.Socks_Packet + Length(Socks5_Request.Socks_ID)));
end;
</code></pre>

<p>I'm pretty sure the problem is on SendBuf second parameter, where I specify the count of bytes to be sent. What is the correct approach, and how I should study to learn it?</p>