jon_bondy 1 Posted October 28, 2019 This code was working in Android before I was forced to upgrade to Delphi10.3 Community Edition. I open some text files and display them in a memo. Sometimes the user selects a file from the list of files in the Documents folder. Sometimes the user opens the "next" file in the Documents folder. When the user opens the "next" file in the Documents folder, the file displays correctly, at the top of the file. When the user opens a file by selecting it from the list, the file scrolls all the way to the bottom. I have tried everything that I can think of to force the memo to go to the top, to no avail. I use the same procedure to open all files in all cases. It consists of fName := ASelectedItem; ScrollOff; Memo1.Lines.LoadFromFile(fName); Memo1.ScrollToTop; Memo1.GoToTextBegin; Memo1.SetFocus; where ASelectedItem is passed in as a string parameter, and ScrollOff turns off an automatic scrolling feature that I implemented and almost never use. I realize that seeing only this code fragment it is difficult for anyone to figure out what I've done wrong, but I hope that the hint that I transitioned from 10.2 to 10.3 may suggest something to someone who is more experienced in these two releases than I am (or experienced with the underlying Android SDKs). I have to say that being forced to upgrade to 10.3 has cost me an enormous amount of time while not changing any useful functions of which I am aware. If someone can point me to documentation about how to take a snapshot of my project so that I can upload it, I will do so. Thanks. Jon Share this post Link to post
eivindbakkestuen 47 Posted October 29, 2019 2 hours ago, jon_bondy said: where ASelectedItem is passed in as a string parameter, and ScrollOff turns off an automatic scrolling feature that I implemented and almost never use. What happens if you don't use that automatic scrolling at all? First guess is, it's still kicking in. Share this post Link to post
jon_bondy 1 Posted October 29, 2019 Thanks for the suggestion. I disabled the automatic scrolling and the problem still persists. Share this post Link to post
Lars Fosdal 1793 Posted October 29, 2019 Is there any difference in behaviour if you SetFocus GoToTextBegin ScrollToTop instead? Can you reproduce the problem in a minimal app? Share this post Link to post
jon_bondy 1 Posted October 29, 2019 I tried the order you recommended and the behavior does not change. The app is actually very minimalist, except for a file selector that I found somewhere. That is a separate module, with a callback routine which is invoked when the file is selected. When the LoadFile() procedure is called as a call back, the bad scrolling behavior occurs; when it is called directly, with a file name, the file is correctly positioned in the memo. Share this post Link to post
jon_bondy 1 Posted October 29, 2019 Well. Maybe here is a clue. When I perform the "next" function, the memo APPEARS to be correctly positioned. But if I tap somewhere in the text, suddenly it scrolls to the end, as if it was really at the end the whole time. None of this is how it behaved a month or two ago, before I was forced to upgrade Delphi. Puzzling and frustrating. Share this post Link to post
Attila Kovacs 631 Posted October 29, 2019 Why is this thread in RTL and DOP? Share this post Link to post
jon_bondy 1 Posted October 30, 2019 If I have posted this in the wrong place, I welcome moving it to the appropriate location. Share this post Link to post
Lars Fosdal 1793 Posted October 30, 2019 No worries. I moved it to VCL. What if you try: SendMessage(Memo1.Handle, EM_SCROLLCARET, 0, 0); instead of the goto/scrollto ? Share this post Link to post
jon_bondy 1 Posted October 30, 2019 @Lars Fosdal: Thanks for the suggestion. Does SendMessage work on Android? When I try to use that procedure, it is undefined. Does it live in some module that I need to Use? Share this post Link to post
Lars Fosdal 1793 Posted October 30, 2019 ah no - dang - I missed that it was Android. Moved the post again. 1 Share this post Link to post
jon_bondy 1 Posted October 31, 2019 Stranger and stranger. I have disabled all timers (which I use for scrolling) and the problems still persist. I noticed that the files first appear in the correct position, scrolled to the top, and then scroll down (instantly) after about 1/2 second. It is as if a timer went off after 1/2 second, but there are no timers to do the scrolling. I've also noticed that some files scroll to the end while others just scroll 1/2 of a line height. Yeah. Right. This is reproducible, as if the TMemo is displaying different files differently based on content or file name. Clearly, I cannot have written such complex code by accident and then not noticed it while debugging recently. And, it was working just fine a month ago. Of course, by now, with all of my flailing, the code is not precisely as it was a month ago. I have attached a ZIP with some files. I hope I have provided the right files for someone to compile my program: if not, please ask for what you need. I have also included two TXT files that you should put in your Documents folder. Those files should be visible if you tap on the Open button. If I open the Jolene file here, it scrolls to the end; if I open the Honky Tonk Blues file here, it scrolls down 1/2 of a line. When I tap on Prev or Next, the files open without scrolling. The program was written as a quick hack. The "buttons" just look like words across the top of the screen. JLBPrompter.zip 1 Share this post Link to post
Dave Nottage 563 Posted November 17, 2019 In your TfmSelect.btnSelectClick method, move the Close statement to the beginning of the method. Share this post Link to post
jon_bondy 1 Posted November 18, 2019 @Dave Nottage: Thanks for your help! Your suggestion fixed the problem, but the program behavior remains mysterious. Suppose that my TMemo already is loaded with song Fred. I then try to Open song Joan. After I select Joan, the selection screen clears and I see the leftover Fred (good). Then Fred scrolls all the way to the bottom (mysterious but harmless). Then Joan loads properly at the top. I don't understand what is going on, but at least the app is working again. Thanks again! Jon Share this post Link to post