I have a TIBquery object on one of the forms, which performing a heavy query, and the form freezing for a while.
- Could this “freezing” be prevented, and how ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The database query is blocking your UI thread. Use a background thread for your query. A similar topic is already covered here and here.
You asked for an example, so here is one. Note that code is pseudo since it works with a plain
TQuery, skips all the setting up, tearing down, error checking and is contained directly in the main form’s unit. It just illustrates one way to solve your problem.This works fine for the DB components I use. Be careful not to do any UI related activities in the
Execute. The code shares aTQuerybetween the main thread and the query thread. It might be necessary that you not only create the query inside the thread, but also the database connection. You should probably use one connection per every thread you query the database from.