[Solved] Index of first line or char displayed in TMemo lazarus / 31-LCL ---------------------------------------------------------------------- lorenzo · 2021-02-19 06:17 I can highlight text in a TMemo programmatically, using selstart and sellength.  I'd like to scroll the TMemo (in code) to position the selection somewhere mid-screen.  I have found how to use TMemo.ScrollBy but still have a problem identifying the screen position of the selection.  TMemo.VertScrollBar will tell me its Min, Max, and Position, but I cannot see how to relate those values to TMemo.SelStart or TMemo.CaretPos values. Can you give me a suggestion please?  The equivalent operation with a TListBox is easy: just adjust TopIndex to make the difference from ItemIndex suitable.  That would be good enough if I were selecting entire lines, but I'm trying to work with selection of part of a line.  I'm frustrated that I cannot work it out in a TMemo.  System: Windows 10, latest updates; Lazarus 2.0.6 (FPC 3.0.4 SVN 62129) i386-win32-win32/win64 ---------------------------------------------------------------------- balazsszekely · 2021-02-19 14:59 @lorenzo QuoteI can highlight text in a TMemo programmatically, using selstart and sellength.  I'd like to scroll the TMemo (in code) to position the selection somewhere mid-screen.  I have found how to use TMemo.ScrollBy but still have a problem identifying the screen position of the selection.  TMemo.VertScrollBar will tell me its Min, Max, and Position, but I cannot see how to relate those values to TMemo.SelStart or TMemo.CaretPos values. Can you give me a suggestion please? The equivalent operation with a TListBox is easy: just adjust TopIndex to make the difference from ItemIndex suitable.  That would be good enough if I were selecting entire lines, but I'm trying to work with selection of part of a line.  I'm frustrated that I cannot work it out in a TMemo. System: Windows 10, latest updates; Lazarus 2.0.6 (FPC 3.0.4 SVN 62129) i386-win32-win32/win64 I attach a windows only solution. Press the "Select" button, then scroll up or down so the selected text is no longer visible. Press the "Scroll" button to scroll the selected text into view. The memo behaves like a TListBox combined with TopIndex property. ---------------------------------------------------------------------- lorenzo · 2021-02-20 15:08 Brilliant, GetMem!  Thank you so much.  I'll enjoy getting that to work in my own code. L.