TMemo scroll down (stupid question alert) lazarus / 31-LCL ---------------------------------------------------------------------- Weiss · 2024-10-07 21:18 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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 · 2024-10-07 21:30 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 ---------------------------------------------------------------------- jamie · 2024-10-07 22:46 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Sendmessage(Memo1.Handle, EM_LINESCROLL, 0,32767); ---------------------------------------------------------------------- hcoenen · 2024-10-07 23:27 memo1.caretpos:=point(0,memo1.lines.count-1) ? ---------------------------------------------------------------------- Weiss · 2024-10-08 00:29 Quote from: hcoenen on October 08, 2024, 01:27:58 ammemo1.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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i memo1.Lines.Add(outputString)it does not. I am still studying Mark's example ---------------------------------------------------------------------- TRon · 2024-10-08 00:34 @Weiss: The behaviour as described looks similar to that for GTK, the following tries to fix that: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   {$ifdef linux}  Memo1.selstart := MaxInt;  {$endif} ---------------------------------------------------------------------- Weiss · 2024-10-08 00:50 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 · 2024-10-08 01:54 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  Memo1.selstart := Length(Memo1.text); ---------------------------------------------------------------------- fpcoder · 2024-10-08 03:12 TSynedit can move to a line by changing the CaretY value: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SynEdit.CaretY:=SynEdit.Lines.Count; You may have to disable the horizontal scrollbar if it's obscuring the last line. ---------------------------------------------------------------------- Joanna · 2024-10-08 06:34 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. ---------------------------------------------------------------------- MarkMLl · 2024-10-08 06:54 Quote from: TRon on October 08, 2024, 03:54:30 amThat 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i memo.Lines.BeginUpdate;try  memo.Lines.Append(line)finally  memo.Lines.EndUpdateend  MarkMLl ---------------------------------------------------------------------- TRon · 2024-10-08 07:00 Quote from: MarkMLl on October 08, 2024, 08:54:39 amHold 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. ---------------------------------------------------------------------- jamie · 2024-10-08 10:52 Quote from: jamie on October 08, 2024, 12:46:37 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Sendmessage(Memo1.Handle, EM_LINESCROLL, 0,32767);     [/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. ---------------------------------------------------------------------- Joanna · 2024-10-08 11:26 Quote from: jamie on October 08, 2024, 12:52:04 pmQuote from: jamie on October 08, 2024, 12:46:37 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Sendmessage(Memo1.Handle, EM_LINESCROLL, 0,32767);     [/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? ---------------------------------------------------------------------- Weiss · 2024-10-14 12:19 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ..try s:=memInput.Text if lua_load buffer....//etc//.. more codeexcept  outputString:=lua_toString(L,-1);  memOutput.Lines.Append(outputString);..  but this works Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i s:=memInput.text;..//same code but not wrapped in try- except..memOutput.Lines.append(outputString) ---------------------------------------------------------------------- Joanna · 2024-10-15 01:34 I seldom use try except, is there a way to check the conditions which might cause an error without the try except? ---------------------------------------------------------------------- Weiss · 2024-10-15 08:58 Quote from: Joanna on October 15, 2024, 03:34:27 amI 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. ---------------------------------------------------------------------- MarkMLl · 2024-10-15 09:13 Quote from: Joanna on October 15, 2024, 03:34:27 amI 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 ---------------------------------------------------------------------- Joanna · 2024-10-15 12:15 Quote from: MarkMLl on October 15, 2024, 11:13:09 amQuote from: Joanna on October 15, 2024, 03:34:27 amI 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?? ---------------------------------------------------------------------- MarkMLl · 2024-10-15 13:32 Quote from: Joanna on October 15, 2024, 02:15:42 pmWould 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 ---------------------------------------------------------------------- Joanna · 2024-10-15 15:06 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!