I use a TextArea in one of my Gambas applications (QT). As my program operates, it periodically adds lines of status updates to the bottom of the TextArea. These updates contain various information such results of tests, sizes of files, the time operations have taken. etc.
As the program cycles through its tasks, repeating forever, it periodically adds another line of text at the bottom of the TextArea. I'm able to scroll up, if needed, to compare the current block of statuses to what happened 10 minutes ago, 30 minutes ago, etc. Because the data its crunching is always changing and never the same.
The problem is: over time, the program's GUI becomes sluggish, eventually non-responsive, due to the TextArea buffer size inevitably becoming filled.
I've worked around this by using the following example code in Timer1 (1000 ms). It removes all but the more recent status updates from TextArea1.:
Dim TempString as String
If TextArea1.Length > 5000 Then
TempString = TextArea1.Text
TextArea1.Text = Null
TextArea1.Text = Right(TempString, 1000)
TextArea1.Pos = TextArea1.Length
TextArea1.EnsureVisible
TempString = Null
EndIf
I'm also using this code in the TextArea's change eventPublic Sub TextArea1_Change()
TextArea1.Pos = TextArea1.Length
TextArea1.EnsureVisible
End
This solves the problem of the program's GUI becoming sluggish over time, due to an ever-growing buffer. However, as for keeping the TextArea scrolled to the bottom, as the latest line of text is added, sometimes it works and sometimes it doesn't. When it doesn't work, the TextArea will be scrolled to the very top, instead of the bottom. And then, when a new line of text is added, the TextArea jumps to the bottom and instantaneously jumps back to the top.
This has got me completely stumped. I don't recall ever having this problem before Gambas 3.15. But I'm not saying its a Gambas bug. Its much more likely a peculiarity of this particular program I've created.
I know you guys are the best of the best. And I have no doubt some of you have much better and cleaner methods of handling both the TextArea buffer issue and the scrolling issue. Thanks for any help or suggestions.
Gambas 3.15.2
Linux Mint 20 Ulyana 64-bit
Kernel Linux 5.4.0-52-generic x86_64
MATE 1.24.0