Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6837443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:28:40+00:00 2026-05-26T23:28:40+00:00

I have a TIBquery object on one of the forms, which performing a heavy

  • 0

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 ?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:28:41+00:00Added an answer on May 26, 2026 at 11:28 pm

    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.

      //  Create a descendant of TThread. This thread will execute your query
      //  asynchronously.
      TMyQueryThread = class(TThread)
      private
        FQueryString: string;
        FMyQuery: TQuery;
      protected
        procedure Execute; override;
      public
        constructor Create(QueryString: string);
        destructor Destroy; override;
        property MyQuery: TQuery read FMyQuery;
      end;
    
    //  This processes the query result. Do whatever you need to do with the data,
    //  but remember to do it quick. Otherwise you will freeze your UI again.
    procedure ProcessResult(Data: TDataSet);
    begin
      // process the data
      while not Data.Eof do
        Data.Next;
    end;
    
    //  This will be called when the thread terminates. 
    //
    //  Context: The code in here is executed in the main thread.
    procedure TForm1.HandleThreadTerminate(Sender: TObject);
    var
      SourceThread: TMyQueryThread;
    begin
      SourceThread:= TMyQueryThread(Sender);
      // invoke data processing
      ProcessResult(SourceThread.MyQuery);
    end;
    
    //  When the user decides to run the query we create our thread. This call 
    //  will take minimal time, so it doesn't block the UI.
    //
    //  Context: The code in here is executed in the main thread.
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      with TMyQueryThread.Create('SELECT * FROM Table') do
      begin
        // we want to know when the thread finished its work so register for the event
        OnTerminate := HandleThreadTerminate;
        // this will free the thread object after OnTerminate has been called
        FreeOnTerminate := True;
      end;
    end;
    
    { TMyQueryThread }
    
    //  Constructor of the thread class. This takes the sql string to be executed.
    //
    //  Context: In this example, the code in here is executed in the main thread.
    constructor TMyQueryThread.Create(QueryString: string);
    begin
      // don't forget to call inherited constructor; tell it to start running immediately
      inherited Create(False);
      // save query string
      FQueryString := QueryString;
    end;
    
    //  Do the work which used to freeze your UI.
    //
    //  Context: The code in here does NOT run in the main thread.
    procedure TMyQueryThread.Execute;
    begin
      // mock query - this is your TIBQuery
      FMyQuery:= TQuery.Create(nil);
      with FMyQuery do
      begin
        SQL.Text:= FQueryString;
        // this will take a while but it doesn't matter because it only blocks the current thread, not the main thread
        Open;
      end;
    end;
    
    destructor TMyQueryThread.Destroy;
    begin
      FMyQuery.Free;
      inherited;
    end;
    

    This works fine for the DB components I use. Be careful not to do any UI related activities in the Execute. The code shares a TQuery between 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have Googled the cr*p out of this one so apologies if the answer is
Have the following scenario. I have a few form, which essentially have a few
Have seen that this piece of code could solve my problems but I don't
Have seen multiple posts on this but I can't see any which answer my
have such zend query: $select = $this->_table ->select() ->where('title LIKE ?', '%'.$searchWord.'%') ->where('description LIKE
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you managed to get Aptana Studio debugging to work? I tried following this,
Have converted devise new session from erb to Haml but doens't work, this is
have anyone can tell me what syntax error on this actionscript (actionscript3.0)? var rotY:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.