Solved

Update progress bar

Posted on 2009-07-01
2
414 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month5 days, 7 hours left to enroll

627 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