No need, .Text will always append a newline, so what you have to do is just trim that new line (but don't use Trim(Right), as it may remove ALL whitespace characters from the end).
No, Memo.Text := Memo.Text + string will
not add a newline.
TMemoryStream.ReadAnsiString expects to read first string length information (saved as 4 byte sequence) from current stream position and after that the whole string. So using it won't be acceptable solution in this situation because there is no string lengths saved in first place. TProcess reads output from console program in raw without processing it further.
You're correct. ReadAnsiString is not the correct way (like I initially thought). I thought it would read an AnsiString from the Stream but it doesn't. It reads a typed string from the stream (indeed with the size prefixed like the old pascal string). It's only used in combination with TMemoryStream.WriteAnsiString (which puts the length on the stream too).
I still feel like directly using the TMemoryStream can be used correctly. Look at the following code (Button1, Button2 and a Memo1 on a form):
Button1 just adds "text. " to the memo. It will all be on one line so it demonstrates Text := Text + string does not add newlines.
Button2 puts a "line 1" with linebreak and "line 2"
without linebreak in the memo. When using Button2 multiple times you'll see that after "line 2" there is really
no linebreak. So you can use this FMemStream as a rawbuffer type. There is absolutely no need to check for #13 anywhere. It just directs all raw output to the memo and there is no issue when that output hasn't a ending linebreak. The next portion will just be added to the previous line.
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Text := Memo1.Text + 'text. ';
end;
function MemoryStreamToString(M: TMemoryStream): AnsiString;
begin
SetString(Result, PAnsiChar(M.Memory), M.Size);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
FMemStream: TMemoryStream;
Str: AnsiString;
begin
FMemStream := TMemoryStream.Create;
try
FMemStream.Clear;
str := 'lines 1' + #13;
FMemStream.Write(str[1], Length(str));
str := 'lines 2';
FMemStream.Write(str[1], Length(str));
Str := MemoryStreamToString(FMemStream);
Memo1.Text := Memo1.Text + Str;
finally
FMemStream.Free;
end;
end;