Solved

Update progress bar

Posted on 2009-07-01
2
410 Views
Last Modified: 2013-11-23
I have a form and an alert dialog which contain a progress bar.
How to update it from the form? If i want to update it also from
a thread should I create a specific progressbar class in a way that
is able to handle postmessage from the thread?
0
Comment
Question by:jaja2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 4

Expert Comment

by:JonasMalmsten
ID: 24756038
Just reference the form and the progressbar, like

Form2.ProgressBar1.Position := ...;

If this doesn't make sense, how do you create the alert form?

In almost all cases I would say that a thread should not be aware of the progressbar (or any other graphical components). It is usually better to isolate GUI components from data processing components. One way to do this is to create an event property in your thread class, see TNotifyEvent and the TThread.Synchronize method. The form containing the progressbar can then hook the event and update its own progressbar. If you tell me a little more about what your thread is doing maybe I can suggest a better solution.
0
 
LVL 4

Accepted Solution

by:
JonasMalmsten earned 500 total points
ID: 24756795
I just read your other questions... is there a reason why you don't want to use Synchronize?

The key thing here is to conform to the Model-View pattern. Consider the thread being your Model and the form being your View. By declaring a TNotifyEvent (or any other custom event) in your thread class your Model will not know anything about your View, and the View can use its knowledge about the Model to update itself.

Using events would be the standard delphi way for doing this but you can accomplish almost the same thing by having the thread send a windows message to the main form. The message should then be just a notification to the main form that something in the thread class has changed. For example that partial work was completed. The main form can the use properties of functions declared in the thread to update the progressbar and any other GUI components. Think about it this way, what if one day you want to replace the progressbar to something different or maybe use 2 progressbars. This should not require you to change any code inside your thread.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question