View Issue Details

IDProjectCategoryView StatusLast Update
0037673Lazarus-public2021-04-14 03:35
ReporterRussell Crosser Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Summary0037673: Unreliable scroll of memo using vertscrollbar.position
DescriptionBug in Memo scrolling.
Setup:
HP Laptop 15-bw0xx,
Windows 10, Lazarus 2.06, 2020-04-24
FPC 3.0.4 SVN Revision 62129
x86_64-win64-win32/win64

Problem: I am trying to scroll a memo accurately to a highlighted line by setting Memo1.VertScrollBar.Position = desired line number.
It generally works, but if I use the mouse scrollwheel to change the view, the positioning is no longer accurate, and the
highlighted text may be outside the visible area. This remains so through some further searches. The system corrects if
I manually scroll the vertical scrollbar to zero.

Workaround:
It works reliably if I use
SendMessage(Memo1.Handle, EM_LINESCROLL, 0, n - Memo1.VertScrollBar.Position)

Previous report?
A similar problem was reported in Lazarus forum:
Setting TMemo.VertScrollBar.Position does not scroll the text field
« on: November 22, 2015, 02:36:56 am »
That was where I got the workaround. It doesn't seem to be fixed, or it is a slightly different bug.

Russell Crosser russell.crosser@gmail.com
Steps To ReproduceSet Memo1.VertScrollBar.Position to a chosen line beyond the last visible line. the memo scrolls to it. Use the mouse
scroll wheel to change the view downward (text going up), even by only 1 line. Set Memo1.VertScrollBar.Position to 0.
Memo scrolls to a low number, but the first line is not visible, along with zero to a few more lines. It remains inaccurate
through a few or many further iterations, but corrects itself if I scroll to the top with the vertical scrollbar.
Works fine if I don't use the wheel.
Additional InformationSee sample program and screen dump.
TagsNo tags attached.
Fixed in Revision
LazTarget
Widgetset
Attached Files

Activities

Russell Crosser

2020-08-31 22:34

reporter  

MemoScroll.zip (129,750 bytes)
MemoScroll.png (13,226 bytes)   
MemoScroll.png (13,226 bytes)   

Serge Anvarov

2020-09-01 17:39

reporter   ~0125282

Last edited: 2020-09-01 17:40

View 2 revisions

To work this correctly, you need:
1. Synchronize the internal state of the position with the actual state, since it is cached. To do this, just call any read method, such as Memo1.VertScrollBar.GetPosition (without assignment!), before starting the changes.
2. Set cursor position first: Memo1.CaretPos := ...; Memo1.SetFocus;
3. Set scroll position: Memo1.VertScrollBar.Position := n;
[code]
Memo1.VertScrollBar.Position;
Memo1.CaretPos := Point(0, i);
Memo1.SelLength := 6;
Memo1.SetFocus;
Memo1.VertScrollBar.Position := n;
[/code]

Russell Crosser

2021-04-14 03:35

reporter   ~0130363

Thank you, I will try this.

Issue History

Date Modified Username Field Change
2020-08-31 22:34 Russell Crosser New Issue
2020-08-31 22:34 Russell Crosser File Added: MemoScroll.zip
2020-08-31 22:34 Russell Crosser File Added: MemoScroll.png
2020-08-31 22:48 Jonas Maebe Project FPC => Lazarus
2020-09-01 17:39 Serge Anvarov Note Added: 0125282
2020-09-01 17:40 Serge Anvarov Note Edited: 0125282 View Revisions
2021-04-14 03:35 Russell Crosser Note Added: 0130363