A new line inside the line will be shown on TMemoBox

I am creating a String called FullMemo that will appear in the TMemoBox , but the problem is that I am trying to make such strings as follows:

 FullMemo := txtFistMemo.Text + '\n' + txtDetails.Text 

I got the contents of the txtFirstMemo character \n , not the newline and the contents of txtDetails . What should I do to make a new line work?

+6
variables string delphi lazarus memo
source share
5 answers

The solution should use # 13 # 10 or better, as Sertac suggested sLineBreak .

 FullMemo := txtFistMemo.Text + #13#10 + txtDetails.Text; FullMemo := txtFistMemo.Text + sLineBreak + txtDetails.Text; 
+20
source share

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 new line that you can use:

 Strings.Add(''); 
+4
source share

Use

 FullMemo := txtFistMemo.Text + #13#10 + txtDetails.Text 
+3
source share

You do not make newlines, for example, you use character # 13:

 FullMemo := txtFistMemo.Text + #13 + txtDetails.Text + Chr(13) + 'some more text'#13. 

# 13 - CR, # 10 - LF, sometimes it’s enough to use only CR, sometimes (for writing text files, for example) use # 13 # 10.

+1
source share

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 very convenient.

0
source share

All Articles