Recent

Author Topic: odd behaviour when adding to a TMemo  (Read 649 times)

robert rozee

  • Full Member
  • ***
  • Posts: 153
odd behaviour when adding to a TMemo
« on: May 28, 2020, 07:03:01 pm »
hi all,
    i've encountered an odd bit of behaviour with a memo, triggered by adding blank lines. attached is a small test project that demonstrates the behaviour.

the problem: basically, if you add some blank lines to the end of a memo using Memo1.Lines.Add(''), and then add characters to the end of the last line of the memo using Memo1.Lines[Memo1.Lines.Count-1]:=Memo1.Lines[Memo1.Lines.Count-1]+'abc.', then the previously added blank lines are removed one at a time.

see the attached example, using Lazarus 2.0.6: click the left button to clear both memos. next click the middle button half a dozen times to add some 'blank' lines. true blank lines ('') are added to the left memo, while 'fake' blank lines ('-') are added to the right memo. now click on the right button several times to add some characters to the last line of each memo - each time you click the right button one of the blank lines in the left memo is deleted and the line count goes down by 1. the right memo behaves normally.

in the production code i've been working on, i can get around this just by adding lines containing a single space, so the problem is more academic than anything else.


is this a known issue with memos?


cheers,
rob   :-)

bytebites

  • Hero Member
  • *****
  • Posts: 632
Re: odd behaviour when adding to a TMemo
« Reply #1 on: May 28, 2020, 07:33:46 pm »
Trunk version behaves similarly.

Code: Pascal  [Select][+][-]
  1.  memo1.Append('abc.');
works correctly.

robert rozee

  • Full Member
  • ***
  • Posts: 153
Re: odd behaviour when adding to a TMemo
« Reply #2 on: May 28, 2020, 07:55:08 pm »
unfortunately - for me at least:
Code: Pascal  [Select][+][-]
  1. Memo1.Append('abc.')
adds the text on a new last line (not the desired behaviour), whereas:
Code: Pascal  [Select][+][-]
  1. Memo1.Lines[Memo1.Lines.Count-1]:=Memo1.Lines[Memo1.Lines.Count-1]+'abc.'
adds the text on to the end of the existing last line.


cheers,
rob   :-)

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: odd behaviour when adding to a TMemo
« Reply #3 on: May 28, 2020, 08:30:23 pm »
if you are on Windows use messages...

WM_SETSEL //Position the setpoint at the end of the string -1
WM_REPLACESEL,  inserts a new content.

The only true wisdom is knowing you know nothing

robert rozee

  • Full Member
  • ***
  • Posts: 153
Re: odd behaviour when adding to a TMemo
« Reply #4 on: May 28, 2020, 08:33:47 pm »
linux i'm afraid.


cheers,
rob   :-)

 

TinyPortal © 2005-2018