Jump to content
uniGUI Discussion Forums
Sign in to follow this  
sagt3k

Refresh label during big loop/elaboration

Recommended Posts

I often work on a database as a data matrix, and then to use nested loops that take time. During the running I use labels and make Application.ProcessMessages to display the updated label.

On using UniGUI on the web, the labels are not updated until end the loop. How can I fix this? During these cycles, I'd use other button to make other function on form, for example, always using Application.ProcessMessages, but that does not work. How can I fix this?

Share this post


Link to post
Share on other sites

Application.ProcessMessages is a VCL thingy and has no affect on how Web mode works. Actually it can crash your app and its usage is discouraged.

Share this post


Link to post
Share on other sites

Thanks for the advice, so how do I refresh a label in a loop?

I have not done this yet with UniGUI but I did it with another framwork. This is one way to do this (I suppose that your process is done on server side):

  • use a thread to process the loop in parallel (parallel thread), so that does not block any kind of messages
  • use a timer to refresh (to generate activity on main thread to, i.e. refresh your label) periodically every N seconds

 

You can do your loop inside a thread. Inside it, you can modify any property provided you have in mind that YOU MUST synchronize this action with the main thread.

 

You can use standard TThread and Synchronize mechanism provided in VCL but I prefer the TJvThread of the JVCL component library (http://jvcl.delphi-jedi.org/) because you can use the thread as any other component, from the standpoint of the accessing to other components of the form, database connections, etc. as long as you make sure that you use a TCriticalSection to ensure correct concurrency updating any property (inside your execute method of the thread, use .Enter method of TCriticalSection, update the label and other properties and, finally use TCriticalSection.Leave method).

 

Please, be very careful avoiding any access to form or components properties out of a critical section.

 

You have to enable the timer before starting the thread and, ontimer event, you could see if the thread is still active. If not, disable the timer.

Share this post


Link to post
Share on other sites

I had thought about creating a table that is updated by different threads. You could use the SessionID as a key. And a timer that goes for every xx seconds, a control record to see in what state are the threads, then put into a listbox the same status.

Share this post


Link to post
Share on other sites

I had thought about creating a table that is updated by different threads. You could use the SessionID as a key. And a timer that goes for every xx seconds, a control record to see in what state are the threads, then put into a listbox the same status.

Please look at http://forums.unigui.com/index.php?/topic/1479-progressbar-multithreading-demo/

It contains a simple example showing how to do this with UniGUI.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×