Recent

Author Topic: [SOLVED] Unwanted additional line in the end of TRichMemo.  (Read 793 times)

CM630

  • Hero Member
  • *****
  • Posts: 1220
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
[SOLVED] Unwanted additional line in the end of TRichMemo.
« on: December 13, 2024, 04:12:25 pm »
I have added a RichMemo to a form. I have entered two lines in RichMemo1.Lines.
But when I run the app there is an empty third line.
Can I get rid of it?
I tried to set RichMemo1.ReadOnly := True, but it does not help, the line is still there.
A sample project is attached.
« Last Edit: January 13, 2025, 02:32:18 pm by CM630 »
Лазар 4,0RC2 32 bit (sometimes 64 bit); FPC3,2,2

cdbc

  • Hero Member
  • *****
  • Posts: 1779
    • http://www.cdbc.dk
Re: Unwanted additional line in the end of TRichMemo.
« Reply #1 on: December 13, 2024, 04:32:57 pm »
Hi
Maybe:
Code: Pascal  [Select][+][-]
  1. { we don't want that pestering last empty line }
  2. RichMemo1.Lines.SkipLastLineBreak:= true;
this could work?!?
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0


Ten_Mile_Hike

  • Jr. Member
  • **
  • Posts: 91
Re: Unwanted additional line in the end of TRichMemo.
« Reply #3 on: December 13, 2024, 09:34:47 pm »
The other responses are best, but there is always *Untested*
Code: Pascal  [Select][+][-]
  1. Memo1.text:=Leftstring(Memo1.text,Length(memo1.text)-1)  {or -2 if your line is #13#10}
  2.  
When any government, or any church for that matter, undertakes to say to its subjects, This you may not read, this you
must not see, this you are forbidden to know, the end result is tyranny and oppression no matter how holy the motives.

Robert A. Heinlein

CM630

  • Hero Member
  • *****
  • Posts: 1220
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Unwanted additional line in the end of TRichMemo.
« Reply #4 on: December 14, 2024, 08:55:13 am »
None of these works:

Code: Pascal  [Select][+][-]
  1.  RichMemo1.Lines.SkipLastLineBreak := True;
  2.  RichMemo1.Lines.TrailingLineBreak := False;
  3.  RichMemo1.Lines.Options := RichMemo1.Lines.Options - [soTrailingLineBreak];

I uploaded the snippet with them and attached it.


...
Code: Pascal  [Select][+][-]
  1. Memo1.text:=Leftstring(Memo1.text,Length(memo1.text)-1)  {or -2 if your line is #13#10}

...

The last #13#10 is not in the text, but it is displayed, this is the problem. Memo1.text:='1'#13#10'2'; still shows an empty third line.

EDIT: I tried again on another PC (still not sure what is different). Memo1.text:='1'#13#10'2'; does not show an empty line in the end.
Also I found this https://forum.lazarus.freepascal.org/index.php/topic,28818.15.html, because the issue also occurs in TMemo.
Maybe I will use TKMemo, it does not have this issue.
« Last Edit: December 17, 2024, 07:48:35 am by CM630 »
Лазар 4,0RC2 32 bit (sometimes 64 bit); FPC3,2,2

CM630

  • Hero Member
  • *****
  • Posts: 1220
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Unwanted additional line in the end of TRichMemo.
« Reply #5 on: January 13, 2025, 08:32:42 am »

The issue is solved, more info here:
https://forum.lazarus.freepascal.org/index.php/topic,69804.msg543027.html
Shortly, TRichMemo.Lines.Add shall not be used in this case.
InsertFontText can be used instead (see https://wiki.freepascal.org/RichMemo/FAQ#Add_text_with_font, I have fixed the example).
Лазар 4,0RC2 32 bit (sometimes 64 bit); FPC3,2,2

 

TinyPortal © 2005-2018