Newline Inside a String To Be Shown At a TMemoBox
Question
I'm building a String
called FullMemo
, that would be displayed at a TMemoBox
, but the problem is that I'm trying to make newlines like this:
FullMemo := txtFistMemo.Text + '\n' + txtDetails.Text
What I got is the content of txtFirstMemo
the character \n
, not a newline, and the content of txtDetails
. What I should do to make the newline work?
Solution
The solution is to use #13#10 or better as Sertac suggested sLineBreak.
FullMemo := txtFistMemo.Text + #13#10 + txtDetails.Text;
FullMemo := txtFistMemo.Text + sLineBreak + txtDetails.Text;
OTHER TIPS
A more platform independent solution would be TStringList
.
var
Strings: TStrings;
begin
Strings := TStringList.Create;
try
Strings.Assign(txtFirstMemo.Lines); // Assuming you use a TMemo
Strings.AddStrings(txtDetails.Lines);
FullMemo := Strings.Text;
finally
Strings.Free;
end;
end;
To Add an empty newline you can use:
Strings.Add('');
Use
FullMemo := txtFistMemo.Text + #13#10 + txtDetails.Text
You don't make newlines like this, you use symbol #13:
FullMemo := txtFistMemo.Text + #13 + txtDetails.Text
+ Chr(13) + 'some more text'#13.
#13 is CR, #10 is LF, sometimes it's enough to use just CR, sometimes (when writing text files for instance) use #13#10.
You can declare something like this:
const
CRLF = #13#10;
LBRK = CRLF+ CRLF;
in a common unit and use it in all your programs. It will be really handy.