Quickly moving through a treeview causing crashes.

Posted on 2005-04-22
Medium Priority
Last Modified: 2010-04-05
Been a while since I asked a question, but I wanted to get some thoughts on the best way to handle this scenario.

I have a standard treeview which gets populated at runtime, and then depending on what node you select, it goes to the database to get quite a bit of information each time to populate some frames.

The issue I am having, which I doubt is uncommon, is that if you move up and down the treeview fast using the mouse, the application crashes because it hasnt finished getting the previous information requested at the same time I am asking it to get the next nodes information etc.

What is the best way to handle this? Best way to almost halt the application while it retrieves the data it was asked for, then allow the user to move node again etc etc

Cheers fellow experts
Question by:mikelittlewood
LVL 27

Assisted Solution

kretzschmar earned 200 total points
ID: 13842328
what about to disable the tree temporary and enable after the db.load is ready?
LVL 15

Author Comment

ID: 13842403
Yeah I was wondering if it might be as simple as that, but was also wondering if there was an elegant way to do it.

Currently using the OnChange I set a flag called bMoving to True and then at the end of the OnChange event Im setting it to false.
Then on the OnChanging event Im doing AllowChange := not bMoving so that if it is already trying to do something it wont let the user change node.
Hopefully this is the easiest way to handle the scenario.

Ill hold on and see if anyone else comes up with another suggestion.
LVL 11

Accepted Solution

pcsentinel earned 200 total points
ID: 13842618
Another way that works with DB Searches as well is to kick of a timer on the ONChange event. The timer only needs to be set to 500msecs

So you get lv.OnChange
//this resets the timer value to 500

then in the OnTimer event add the codefor the rest of the work.

This has the effect that if someone just holds down the up or down key then the timer keeps getting reset until the user stops and then the screen updates with the rest.

This works well, I know I've used it thousands of times. but, and ofcouse theres always a but you still need to watch out for the timer firing twice.

What you can do is to have a global Cancel flag and at regular intervals in your main update code check that flag and bail out if neccessary

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 15

Author Comment

ID: 13842636
Thanks for the suggestion pcsentinel.
LVL 14

Assisted Solution

DragonSlayer earned 200 total points
ID: 13843932
or you can have a look at virtualtreeview http://soft-gems.net/VirtualTreeview ... been using that for some time, and haven't had such prob...
LVL 15

Author Comment

ID: 13846568
Cheers for the advice all .. Ill give everyone a share of the points for the info

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question