sagt3k Posted June 14, 2012 Posted June 14, 2012 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? Quote
Administrators Farshad Mohajeri Posted June 14, 2012 Administrators Posted June 14, 2012 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. Quote
sagt3k Posted June 15, 2012 Author Posted June 15, 2012 Thanks for the advice, so how do I refresh a label in a loop? Quote
estrify Posted June 15, 2012 Posted June 15, 2012 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. Quote
sagt3k Posted June 15, 2012 Author Posted June 15, 2012 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. Quote
estrify Posted June 15, 2012 Posted June 15, 2012 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.