In your own program you can use getscrollinfo with sif_all to get the nmin/nmax from the horizontal scrollbars. You can do that before adding a line. Then also do this just before setting the X for horizontal scroll. The nmin/nmax should be the same. If they are not, then the horz scrollbars is not updated directly yet.
I implemented LCLIntf.GetScrollInfo() at several places in my real program. As I assumed (but I was not sure) 'nMax' is independant of a "current" line. It contains always the length in pixels of the longest existing line. 'nMin' is always '0'. So what you assumed in reply #26, from my understanding, can only apply, if the longest line is deleted or shortened, but we only add 1 line.
Here are some results of GetScrollInfo() for vertical + horizontal scrollbars with my real program:
// at the time where all current positions are read and stored (before Memo1.Text is changed):
--GET: style=VERT nMin=0 nMax=65541 nPage=52 nPos=153 nTrack=153
--GET: style=HORZ nMin=0 nMax=1023 nPage=627 nPos=0 nTrack=0
// after Memo1.Text was changed and before vertical position is restored by SetScrollInfo():
--SET-V: style=VERT nMin=0 nMax=65541 nPage=52 nPos=0 nTrack=0
--SET-V: style=HORZ nMin=0 nMax=1023 nPage=627 nPos=0 nTrack=0
// after vertical position was restored and before horizontal position is restored by SetScrollInfo():
--SET-H: style=VERT nMin=0 nMax=65541 nPage=52 nPos=153 nTrack=153
--SET-H: style=HORZ nMin=0 nMax=1023 nPage=627 nPos=0 nTrack=0
// after horizontal position was restored:
--SET-DONE: style=VERT nMin=0 nMax=65541 nPage=52 nPos=153 nTrack=153
--SET-DONE: style=HORZ nMin=0 nMax=1023 nPage=627 nPos=153 nTrack=153
You see in the last line (marked red), that horizontal 'nPos' now becomes 153, but it should be '0' as before.
That is the issue as described before.Then I tested your new demo from reply #26 in my real program, but unfortunately it made no difference :-((
But I made (again, only forgot to mention it here before) a strange observation about the horizontal scrollbar behavior in my real program,
if Memo1.Lines.Count >= 65534:
What still works normally:
- click left or right of the slider in the "empty space" to scroll 1 "page" left or right
- click on the little arrows at the left or right end of the scrollbar to scroll a small amout left or right.
But what does
not work if Memo1.Lines.Count >= 65534 is, to
drag the slider via mouse:
- if I try this, the slider at first moves correctly (corresponding to the mouse movement) as it should, but as soon as I realease the left mouse button, the slider jumps to a wrong position (which has a correlation with the current vertikal scroll position, it jumps often to the very right end position).
- and, if the text currently is scrolled to it's left end (and the slider is at it's left end), in the moment where I click on the slider (wanting to start a drag), at this moment the text itself is automatically scrolled to it's very right end (but the slider stays at it's left end as before). If I release the left mouse button, the slider jumps to the very right end position (the exact target position has also a correlation with the current vertikal scroll position).
If I delete some text lines, so that Memo1.Lines.Count becomes < 65534, this issue stops immediately (without starting the program new or reloading the file). If I then add again some text lines, so that Memo1.Lines.Count becomes >= 65534, the issue occurs again (without starting the program new or reloading the file). The maximum line length is 214 characters.
Tested with Win10 and Win7 with Lazarus 3.6.0, 2.0.10, 1.8.4 and 1.4.4 (needed a large duster ;-)
This happens also directly after program start, without having pressed F5-key ever.
This issue occurs only in my real program (about 64000 lines of code) and
not in rvk's demos in reply #23 and #26, always loading exactly the same textfile.
The vertical scrollbar does not have this issue!
Question:Has anybody an idea, what the reason for such a strange behavior of the horizontal scrollbar might be?