title: How to read all bytes from server using Indy Client in Delphi?
body: <p>I am using Indy client to read the message the server is sending to me (client). It sends 512 bytes of data to me in one go. This 512 bytes of data is composed of two datatypes (Word and String). For example, it sends Word of 2 bytes, then again Word of 2 bytes and then String of 50 bytes and so on. I am trying following code to cope with this problem:</p>
  
  <pre><code>var BufferArray : Array[0..512] of Byte;
  
   if IdTCPClient1.IOHandler.InputBufferIsEmpty then
   begin
        if IdTCPClient1.IOHandler.CheckForDataOnSource(1000) then
        begin
            Edit1.Text := idtcpclient1.IOHandler.ReadBytes(BufferArray ,512, true);
        end;
   end;
  </code></pre>
  
  <p>I am getting error on line Edit1.Text := idtcpclient1.IOHandler.ReadBytes(BufferArray ,512, true); Error: Type of actual and formal var parameter must be identical.</p>
  
  <p>Is it right approach I am using. I want to store whole 512 bytes on Edit1.Text and then will do whatever I want to do with that data. Please help me in getting all 512 bytes from the server.</p>
  
  <p><strong>Update: Alternating Approach</strong></p>
  
  <p>I am using this approach to read word and string values</p>
  
  <pre><code>WordArray : array[0..5] of word;
  
   if IdTCPClient1.IOHandler.InputBufferIsEmpty then
   begin
        if IdTCPClient1.IOHandler.CheckForDataOnSource(1000) then
        begin
          i := 0;
          while i &lt; 6 do //Read all the words
          begin
              //Fill WORD data in array
              WordArray[i] :=  (IdTCPClient1.Socket.ReadWord(True));
          end;
        end;
  end;
  </code></pre>
  
  <p>Similar approach for string like</p>
  
  <p>WordArray[i] :=  (IdTCPClient1.Socket.ReadString(50));</p>
  
  <p>Thats working fine, but I have to remain the connection open while I read all the data in loop. If in between connection goes, I lose everything and have to request the whole package again from server.</p>