Recent

Author Topic: TMemo scroll down (stupid question alert)  (Read 1091 times)

Weiss

  • Full Member
  • ***
  • Posts: 180
TMemo scroll down (stupid question alert)
« on: October 07, 2024, 11:18:30 pm »
there must be some simple command or property in TMemo which would keep last line at bottom of TMemo. Currently when memo window is filled with lines, new lines are populated below the visible window. I added scroll bar and tried different options and properties, like
Code: Pascal  [Select][+][-]
  1. memOutPut.ScrollBy(14,14);
with each added line, but kind of did not make difference. I noticed there is an integer "top" in scrollbar.position, so I can do
Code: Pascal  [Select][+][-]
  1. scrollbar.position:=top;

..but I need "bottom". Or any other way to keep last line visible. This is an outPut "readOnly" window. Must be something trivial.

MarkMLl

  • Hero Member
  • *****
  • Posts: 7859
Re: TMemo scroll down (stupid question alert)
« Reply #1 on: October 07, 2024, 11:30:24 pm »
It's non-trivial. I don't claim to have an immediate answer to your specific problem, but if you look at https://forum.lazarus.freepascal.org/index.php/topic,67337.msg519191.html#msg519191 you'll find code which appends e.g. status lines to a TMemo or TRichMemo without forcing a scroll for a minute or so.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

jamie

  • Hero Member
  • *****
  • Posts: 6681
Re: TMemo scroll down (stupid question alert)
« Reply #2 on: October 08, 2024, 12:46:37 am »
Code: Pascal  [Select][+][-]
  1. Sendmessage(Memo1.Handle, EM_LINESCROLL, 0,32767);    
  2.  

The only true wisdom is knowing you know nothing

hcoenen

  • Newbie
  • Posts: 5
Re: TMemo scroll down (stupid question alert)
« Reply #3 on: October 08, 2024, 01:27:58 am »
memo1.caretpos:=point(0,memo1.lines.count-1) ?

Weiss

  • Full Member
  • ***
  • Posts: 180
Re: TMemo scroll down (stupid question alert)
« Reply #4 on: October 08, 2024, 02:29:00 am »
memo1.caretpos:=point(0,memo1.lines.count-1) ?

you would think. And I thought so too, but no. Caret position will be set, yes, this part works. But memo still shows first line at top and new lines added right were caret position is, at the bottom, outside the window.

Interesting, right? My input memo, where I enter commands, old lines slide up and out of the window, while new lines I enter are always visible at the bottom. Something keeps the new line being entered within a visible part of memo. Here in the forum post window, it works in the same manner. But when new line not entered from keyboard but added
Code: Pascal  [Select][+][-]
  1. memo1.Lines.Add(outputString)
it does not.

I am still studying Mark's example

TRon

  • Hero Member
  • *****
  • Posts: 3453
Re: TMemo scroll down (stupid question alert)
« Reply #5 on: October 08, 2024, 02:34:37 am »
@Weiss:
The behaviour as described looks similar to that for GTK, the following tries to fix that:
Code: Pascal  [Select][+][-]
  1.   {$ifdef linux}
  2.   Memo1.selstart := MaxInt;
  3.   {$endif}
  4.  
This tagline is powered by AI

Weiss

  • Full Member
  • ***
  • Posts: 180
Re: TMemo scroll down (stupid question alert)
« Reply #6 on: October 08, 2024, 02:50:58 am »
TRon, and Jamie, interesting examples, but doesn't work, tried both. Beginning to think there is no simple built-in solution. I will have to boldly keep new lines in an array, and clear memo and display only last few lines which will fit into memo window. Ugly as sin, but this will definitely work. It will involve managing the scroll function manually, but, I have done worse.

TRon

  • Hero Member
  • *****
  • Posts: 3453
Re: TMemo scroll down (stupid question alert)
« Reply #7 on: October 08, 2024, 03:54:30 am »
That is strange. Which platform/widgetset as well as Lazarus version is causing this issue for you ?

BTW: for qt the following was reported to work:
Code: Pascal  [Select][+][-]
  1.  Memo1.selstart := Length(Memo1.text);
  2.  
« Last Edit: October 08, 2024, 04:27:59 am by TRon »
This tagline is powered by AI

kapibara

  • Hero Member
  • *****
  • Posts: 628
Re: TMemo scroll down (stupid question alert)
« Reply #8 on: October 08, 2024, 05:12:45 am »
TSynedit can move to a line by changing the CaretY value:

Code: Pascal  [Select][+][-]
  1. SynEdit.CaretY:=SynEdit.Lines.Count;

You may have to disable the horizontal scrollbar if it's obscuring the last line.
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1173
Re: TMemo scroll down (stupid question alert)
« Reply #9 on: October 08, 2024, 08:34:03 am »
Is there any relationship between the tmemo.vertscrollbar Range and the length of the string list and probably font sizes? I think I would experiment going to last row of memo and seeing what the trackbar position is. Once you know what the position you want is, it should be easy to set it after adding text.
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

MarkMLl

  • Hero Member
  • *****
  • Posts: 7859
Re: TMemo scroll down (stupid question alert)
« Reply #10 on: October 08, 2024, 08:54:39 am »
That is strange. Which platform/widgetset as well as Lazarus version is causing this issue for you ?

I agree. My perennial problem has been making sure that an addition to the memo doesn't make it slam down to the bottom, making it impossible to read older messages.

Hold on, /how/ are you appending to the memo? I'm using

Code: Pascal  [Select][+][-]
  1. memo.Lines.BeginUpdate;
  2. try
  3.   memo.Lines.Append(line)
  4. finally
  5.   memo.Lines.EndUpdate
  6. end
  7.  

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

TRon

  • Hero Member
  • *****
  • Posts: 3453
Re: TMemo scroll down (stupid question alert)
« Reply #11 on: October 08, 2024, 09:00:38 am »
Hold on, /how/ are you appending to the memo? I'm using ...
Indeed you got a point there MarkMLI therefor a good question for TS as well.

FWIW I am also using the append method.
This tagline is powered by AI

jamie

  • Hero Member
  • *****
  • Posts: 6681
Re: TMemo scroll down (stupid question alert)
« Reply #12 on: October 08, 2024, 12:52:04 pm »
Code: Pascal  [Select][+][-]
  1. Sendmessage(Memo1.Handle, EM_LINESCROLL, 0,32767);    
  2.  
[/quote
This works on windows and u do need the windows unit for that.
It will scroll the memo to the end each time u enter text u need to perform this task. Its not a one time function.

 If u r not on windows then I am sorry for wasting yours and my time.
The only true wisdom is knowing you know nothing

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1173
Re: TMemo scroll down (stupid question alert)
« Reply #13 on: October 08, 2024, 01:26:48 pm »
Code: Pascal  [Select][+][-]
  1. Sendmessage(Memo1.Handle, EM_LINESCROLL, 0,32767);    
  2.  
[/quote
This works on windows and u do need the windows unit for that.
It will scroll the memo to the end each time u enter text u need to perform this task. Its not a one time function.

 If u r not on windows then I am sorry for wasting yours and my time.
Is it cross platform? Also how does it work?
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

Weiss

  • Full Member
  • ***
  • Posts: 180
Re: TMemo scroll down (stupid question alert)
« Reply #14 on: October 14, 2024, 02:19:26 pm »
just got time to work on this little snag a little more.

My machine is Panasonic Toughpad FZ G1, OS : Windows 10 the latest, installed September directly from Panasonic support. Lazarus version 3.4 (2024-05-25) FPC 3.2.2

there is issue with sending update to output window (TMemo) from inside try-except wrapper. Whatever solutions were recommended, I tried them all. I can see slider flickers down, and immediately returned back up.

Whenever I move the entire block out of try-except wrapper, TMemo works the way I wanted. New appended lines are at the bottom of visible window of memo, with older lines sliding up outside the window.

this does not work:
Code: Pascal  [Select][+][-]
  1. ..
  2. try s:=memInput.Text
  3. if lua_load buffer....//etc
  4. //.. more code
  5. except
  6.   outputString:=lua_toString(L,-1);
  7.   memOutput.Lines.Append(outputString);
  8. ..
  9.  

but this works
Code: Pascal  [Select][+][-]
  1. s:=memInput.text;
  2. ..//same code but not wrapped in try-except
  3. ..
  4. memOutput.Lines.append(outputString)

 

TinyPortal © 2005-2018