Lazarus

Programming => LCL => Topic started by: Weiss on October 07, 2024, 11:18:30 pm

Title: TMemo scroll down (stupid question alert)
Post by: Weiss 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.
Title: Re: TMemo scroll down (stupid question alert)
Post by: MarkMLl 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
Title: Re: TMemo scroll down (stupid question alert)
Post by: jamie on October 08, 2024, 12:46:37 am
Code: Pascal  [Select][+][-]
  1. Sendmessage(Memo1.Handle, EM_LINESCROLL, 0,32767);    
  2.  

Title: Re: TMemo scroll down (stupid question alert)
Post by: hcoenen on October 08, 2024, 01:27:58 am
memo1.caretpos:=point(0,memo1.lines.count-1) ?
Title: Re: TMemo scroll down (stupid question alert)
Post by: Weiss 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
Title: Re: TMemo scroll down (stupid question alert)
Post by: TRon 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.  
Title: Re: TMemo scroll down (stupid question alert)
Post by: Weiss 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.
Title: Re: TMemo scroll down (stupid question alert)
Post by: TRon 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.  
Title: Re: TMemo scroll down (stupid question alert)
Post by: kapibara 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.
Title: Re: TMemo scroll down (stupid question alert)
Post by: Joanna 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.
Title: Re: TMemo scroll down (stupid question alert)
Post by: MarkMLl 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
Title: Re: TMemo scroll down (stupid question alert)
Post by: TRon 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.
Title: Re: TMemo scroll down (stupid question alert)
Post by: jamie 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.
Title: Re: TMemo scroll down (stupid question alert)
Post by: Joanna 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?
Title: Re: TMemo scroll down (stupid question alert)
Post by: Weiss 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)
Title: Re: TMemo scroll down (stupid question alert)
Post by: Joanna on October 15, 2024, 03:34:27 am
I seldom use try except, is there a way to check the conditions which might cause an error without the try except?
Title: Re: TMemo scroll down (stupid question alert)
Post by: Weiss on October 15, 2024, 10:58:03 am
I seldom use try except, is there a way to check the conditions which might cause an error without the try except?

of course, it is easy to work around. It was just unexpected, that Memo behaves differently when called from try-except. I wonder if this is a bug or a feature.
Title: Re: TMemo scroll down (stupid question alert)
Post by: MarkMLl on October 15, 2024, 11:13:09 am
I seldom use try except, is there a way to check the conditions which might cause an error without the try except?

There was a long thread largely by 440bx on this matter. I suggest that rather than attempting to derail this thread (in your accustomed manner) you would be better off looking for that one, or starting a fresh one.

MarkMLl
Title: Re: TMemo scroll down (stupid question alert)
Post by: Joanna on October 15, 2024, 02:15:42 pm
I seldom use try except, is there a way to check the conditions which might cause an error without the try except?

There was a long thread largely by 440bx on this matter. I suggest that rather than attempting to derail this thread (in your accustomed manner) you would be better off looking for that one, or starting a fresh one.

MarkMLl
Would you mind providing a link to said thread for everyone’s benefit or is your only purpose in life to accuse me of things I didn’t do??
Title: Re: TMemo scroll down (stupid question alert)
Post by: MarkMLl on October 15, 2024, 03:32:56 pm
Would you mind providing a link to said thread for everyone’s benefit or is your only purpose in life to accuse me of things I didn’t do??

Start another thread and I'll see if I can dig it out.

MarkMLl
Title: Re: TMemo scroll down (stupid question alert)
Post by: Joanna on October 15, 2024, 05:06:39 pm
I was just trying to help weiss. I don’t want to start a new thread about things I don’t use. Thank you very much!
TinyPortal © 2005-2018