title: Indy and TStreams
body: <p>What's the best way to go about sending a TMemoryStream through Indy? </p>
  
  <p>At the moment I'm trying:</p>
  
  <pre><code>procedure TClientForm.IdTCPClient1Connected(Sender: TObject);
  begin
    IdTCPClient1.IOHandler.Write(KStore.Size);
    KStore.Position := 0;
    IdTCPClient1.IOHandler.Write(KStore);
  
    Memo1.Lines.Add('Client connected with server');
  end
  </code></pre>
  
  <p>And at the Server end:</p>
  
  <pre><code>function MemoryStreamToString(M: TMemoryStream): string;
  begin
    SetString(Result, PChar(M.Memory), M.Size div SizeOf(Char));
  end;
  
  procedure TClientForm.IdTCPServer1Connect(AContext: TIdContext);
  var
    LStore: TMemoryStream;
    Size: Int64;
    LStore := TMemoryStream.Create;
    LStore.Position := 0;
    Size := AContext.Connection.IOHandler.ReadInt64();
    AContext.Connection.IOHandler.ReadStream(LStore,Size);
  end;
  </code></pre>
  
  <p>But despite a lack of errors, at the other end using that memory stream to string function just returns ???????????????????? in the text file I'm saving it to. </p>