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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:49:22+00:00 2026-05-18T11:49:22+00:00

I have a program running several threads simultaneously. Each thread connects a database and

  • 0

I have a program running several threads simultaneously. Each thread connects a database and transfers data from one table to another. Now I want to assign a panel to each thread in the MainForm so I can change color of the Panel to green if the connection is successful or to red if it’s broken after a number of retries.

So how can I tell a thread which Panel is its own Panel?

  • 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-18T11:49:23+00:00Added an answer on May 18, 2026 at 11:49 am

    When you create a thread class, add a variable to store panel id:

    type
    TMyThread = class(TThread)
    public
      PanelId: integer;
      constructor Create(APanelId: integer);
    end;
    
    constructor TMyThread.Create(APanelId: integer);
    begin
      inherited Create({CreateSuspended=}true);
      PanelId := APanelId;
      Suspended := false;
    end;
    

    For every thread create a panel and set it’s Tag value to this Id:

    for i := 1 to MaxThreads do begin
      threads[i] := TMyThread.Create(i);
      panels[i] := TPanel.Create(Self);
      panels[i].Tag := i;
    end;
    

    When your thread needs to update data on panel, it should send a specially defined message to the main form:

    const
      WM_CONNECTED = WM_USER + 1;
      WM_DISCONNECTED = WM_USER + 2;
    

    In wParam of this message you pass PanelId:

    procedure TMyThread.Connected;
    begin
      PostMessage(MainForm.Handle, WM_CONNECTED, PanelId, 0);
    end;
    

    In MainForm you catch this message, find the panel and update it:

    TMainForm = class(TForm)
      {....}
    protected
      procedure WmConnected(var msg: TMessage); message WM_CONNECTED;
    end;
    
    {...}
    
    procedure TMainForm.WmConnected(var msg: TMessage);
    begin
      panels[msg.wParam].Color := clGreen;
    end;
    

    Same with WmDisconnected.

    The important thing here is that you CANNOT and NEVER should try to update visual components from threads other than the main thread. If you need to update user controls, you should post messages to the main form and create handler procedures, like in this example. These handler procedures will then be automatically called from the main thread.

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

Sidebar

Related Questions

I have a program 'foo' running different threads, fooT1, fooT2, .. fooTn. Now if
In my C# program, I have a thread that represents a running test, which
I have a situation where I might have multiple instances of a program running
What is the best way to have my C# Compact Framework program running in
I have an automated test running on my program that generates some large MPG
I have a program that uses the mt19937 random number generator from boost::random. I
I have a program that spits out both standard error and standard out, and
I have a program that creates a Windows user account using the NetUserAdd() API
I have a program which needs to behave slightly differently on Tiger than on
I have a program that spits out an Excel workbook in Excel 2003 XML

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.