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 985341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:08:56+00:00 2026-05-16T05:08:56+00:00

I am new with this stuff of Threading in Delphi. so, I am trying

  • 0

I am new with this stuff of Threading in Delphi. so, I am trying to make a simple query aplication that make a bit call up for the database and take a bit of time, so I want to alert the user that there is a background process and have to be patient.

I tried many samples, but none of them work for me, Please, could somebody show me a simple sample that could work?

I know that I have to Declare a Type of TThread, with Create and Override Execute… etc.. but since that I am lost…

Using Delphi 7, SQL Server 2005 and ADO, Windows XP sp3.-

Thanks.

  • 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-16T05:08:57+00:00Added an answer on May 16, 2026 at 5:08 am

    You can find many examples on the web of threads. The only special feature, if you are using ADO connections inside the Thread, is that you can’t share the same connection.
    Each thread must create its own connection, otherwise they are equal (should follow the same rules as any other thread.)

    An sample that I have used is this:

      TADOSQLThread = class(TThread)
      private
        FADOQ: TADOQuery;  // Internal query
        FSQL: string;      // SQL To execute
        FID: integer;      // Internal ID
    
      public
        constructor Create(CreateSuspended:Boolean; AConnString:String;
                           ASQL:string; IDThread:integer);
        destructor Destroy; override;
        procedure Execute(); override;
    
        property ID:integer read FID write FID;
        property SQL:string read FSQL write FSQL;
        property ADOQ:TADOQuery read FADOQ write FADOQ;
      end;
    

    The Create constructor is overrided, and look like this:

    constructor TADOSQLThread.Create(CreateSuspended:Boolean; AConnString:String;
                                     ASQL:string; IDThread:integer);
    begin
    
      inherited Create(CreateSuspended);
    
      // ini
      Self.FreeOnTerminate := False;
    
      // Create the Query
      FADOQ := TAdoquery.Create(nil);
      // assign connections
      FADOQ.ConnectionString := AConnString;
      FADOQ.SQL.Add(ASQL);
      Self.FID := IDThread;
      Self.FSQL:= ASQL;
    end;
    

    And the execute method is very simple:

    procedure TADOSQLThread.Execute();
    begin
    
      inherited;
    
      try
        // Ejecutar la consulta
        Self.FADOQ.Open;
      except
        // Error al ejecutar
        ...Error treattement
      end;
    end;
    

    To start and create a thread you can use code similar to this:

      //crear el Thread
      th := TADOSQLThread.Create(True, mmConnection.Lines.Text, ASQL, AId);
      // internal for me (for controled the number of active threads and limete it)
      inc(numThreads);
      // evento finalizacion
      th.OnTerminate := TerminateThread;
      // Ejecutarlo
      th.Resume;
    

    I have create a TerminateThread method that receive the control of threads when they finish. The only different to other threads is the connection problem. You must create a new connection on every thread, It can’t share the same ADOConnections with others.
    I hope this example will be useful for you.

    Regards

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

Sidebar

Related Questions

I am new on this stuff and this could be a simple question, but
Completely new to most of this stuff, but basically Im playing around with the
i am pretty new to all this Monodroid stuff. I am porting my Windows
I am still new to the storyboard stuff. I spent two days debugging this
Okay, I really need some help with this. I'm new with designing and stuff,
New to this library (no more familiar with BeautifulSoup either, sadly), trying to do
I am a bit new to threading (not new to C#, just haven't done
I'm very new to multi-threading and for some reason this class is giving me
I just started messing around with C#/.NET/mono and stuff, and I'm trying to make
I am quite new to C# and threading, and I have this problem to

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.