Recent

Author Topic: [SOLVED] Concatenating text in a TMemo object  (Read 361 times)

Davo

  • Full Member
  • ***
  • Posts: 141
[SOLVED] Concatenating text in a TMemo object
« on: July 01, 2026, 03:00:14 am »
Is it possible to add text to an existing line in a TMemo object? I have tried a number of ways without success. The following code extract illustrates the point.

Code: Pascal  [Select][+][-]
  1. [procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   memo1.lines.Clear;
  4.   memo1.lines.Add('This program shows that none of the following methods concatenates '
  5.     + 'supplied text to text already displayed in a TMemo object :');
  6.   memo1.lines.Add('memo.lines.Add, memo.lines.Append, memo.lines.AddText, memo.Append');
  7.   memo1.lines.Add('  ');
  8.   memo1.lines.Add('Added first string using lines.Add');
  9.   memo1.lines.Append('Appended a string using lines.Append');
  10.   memo1.lines.Append('Appended another string using lines.Append');
  11.   memo1.lines.AddText('Added text using lines.AddText');
  12.   memo1.lines.AddText('Added more text using lines.AddText');
  13.   memo1.lines.Append('Appended yet another string using lines.Append');
  14.   memo1.Append('Appended text at memo level using memo.Append');
  15.   memo1.Append('Appended more text at memo level using memo.Append');
  16. end; ]
  17.  
« Last Edit: July 01, 2026, 03:21:38 pm by Davo »

jamie

  • Hero Member
  • *****
  • Posts: 7832
Re: Concatenating text in a TMemo object
« Reply #1 on: July 01, 2026, 03:23:58 am »
If you understand you correctly..

Code: Pascal  [Select][+][-]
  1.  
  2. Memo.Lines[LineIndex] := Memo.Lines[LineIndex]+'Some added Text';
  3.  

You simply read the line out that you want, play with it like any other text concatening operating and put it back.

But then again, maybe I didn't understand you.

Jamie
The only true wisdom is knowing you know nothing

Davo

  • Full Member
  • ***
  • Posts: 141
Re: Concatenating text in a TMemo object
« Reply #2 on: July 01, 2026, 04:00:28 am »
Thank you Jamie. Yes I believe that you did fully understand my question. I will try your solution and report back.

Davo

  • Full Member
  • ***
  • Posts: 141
Re: Concatenating text in a TMemo object
« Reply #3 on: July 01, 2026, 05:46:03 am »
Yes Jamie that works very well. Thank you. Your help is much appreciated.

n7800

  • Hero Member
  • *****
  • Posts: 734
  • Lazarus IDE contributor
    • GitLab profile
Re: [SOLVED] Concatenating text in a TMemo object
« Reply #4 on: July 03, 2026, 05:05:29 pm »
Let me repeat the reminder from the message: https://forum.lazarus.freepascal.org/index.php/topic,74324.msg585717.html#msg585717

Code: Pascal  [Select][+][-]
  1. Memo.Lines[LineIndex] := Memo.Lines[LineIndex]+'Some added Text';

This insertion can insert text inside a "original" line and also add an extra line break.

 

TinyPortal © 2005-2018