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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:16:39+00:00 2026-06-07T09:16:39+00:00

I have to develop a program to keep watching values in databases based on

  • 0

I have to develop a program to keep watching values in databases based on a Select statement given by me

the watched values can be changed at anytime and my program must sense the changes based on a result of the select statement which is given by me

i want to watch the select result by using TThread because my system is also has another features and the user need to work on it not only to watch values.

how to do it using TThread in Delphi XE2

am using VCL…no .Net

Regards.

  • 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-06-07T09:16:40+00:00Added an answer on June 7, 2026 at 9:16 am

    [Edit]

    Improved answer, now thread runs continuously and “keep watching values”.

    Let’s build a sample.

    First, Create new VCL app. Drop on the form one TListBox and two TButton component. You need to write button click handlers and add one private method. Entire unit should look like this:

    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Unit2;
    
    type
      TForm1 = class(TForm)
        ListBox1: TListBox;
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
        FCollector: TCollector;
        procedure OnCollect(S: TStrings);
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if Assigned(FCollector) then Exit;
      FCollector := TCollector.Create;
      FCollector.OnCollect := Self.OnCollect;
      FCollector.Start;
    end;
    
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      if not Assigned(FCollector) then Exit;
      FCollector.Terminate;
      FCollector := nil;
    end;
    
    procedure TForm1.OnCollect(S: TStrings);
    begin
      ListBox1.Items.AddStrings(S);
    end;
    
    end.
    

    Next we should add our thread, select from menu: File -> New unit and replace with code:

    unit Unit2;

    interface
    
    uses
      System.Classes;
    
    type
    
      TCollectEvent = procedure (S: TStrings) of object;
    
      TCollector = class(TThread)
      private
        { Private declarations }
        FTick: THandle;
        FItems: TStrings;
        FOnCollect: TCollectEvent;
        FInterval: Integer;
      protected
        procedure Execute; override;
        procedure DoCollect;
      public
        constructor Create;
        destructor Destroy; override;
        procedure Terminate;
        property Interval: Integer read FInterval write FInterval;
        property OnCollect: TCollectEvent read FOnCollect write FOnCollect;
      end;
    
    implementation
    
    uses Windows, SysUtils;
    
    { TCollector }
    
    constructor TCollector.Create;
    begin
      inherited Create(True);
      FreeOnTerminate := True;
      FInterval := 1000;
      FTick := CreateEvent(nil, True, False, nil);
    end;
    
    destructor TCollector.Destroy;
    begin
      CloseHandle(FTick);
      inherited;
    end;
    
    procedure TCollector.DoCollect;
    begin
      FOnCollect(FItems);
    end;
    
    procedure TCollector.Terminate;
    begin
      inherited;
      SetEvent(FTick);
    end;
    
    procedure TCollector.Execute;
    begin
      while not Terminated do
      begin
        if WaitForSingleObject(FTick, FInterval) = WAIT_TIMEOUT then
        begin
          FItems := TStringList.Create;
          try
            // Collect here items
            FItems.Add('Item ' + IntToStr(Random(100)));
            Synchronize(DoCollect);
          finally
            FItems.Free;
          end;
        end;
      end;
    end;
    
    end.
    

    Now, when you press Button1, you will receive from thread Items in your combo. Pressing Button2 thread stops executing.

    You should take in account:

    1. Set Interval to watch values, default is 1000ms, see interval property;

    2. All your code (include DB access components) inside Execute and related to it should be thread-save.

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

Sidebar

Related Questions

I develop a Python-based drawing program, Whyteboard . I have tools that the user
I have to develop a program where I need to get the event from
I have program that requires Python 3, but I develop Django and it uses
i have planned to develop a tool that converts a program written in a
I have to develop one program that consists data manipulation (retrieve data, update data
I have to develop a program in C# so that when my Printer is
I have a file with records. I have to develop a spring batch program
I have a program develop for web application(java). I need to send my project
Solution for writing a program for keep secret photos. I have many secret photos
I develop an LDAP interface program which can modify person attributes, but when I

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.