Delaying time stopping the program

I'm working on this LED matrix, but first I decided to write my program for TShape shapes. I'll cahnge their colours and imitate LED switching on and off. The problem is with time delay. I have this neverending loop which changes the view on "LEDs", waits a little, changes the view again and so on. But the thing is, none of the delay methods (I've tried Sleep (), sleep (), clock ()) does what I want them to do. Program is supposed to change colours of shapes, delay, then change again, but my experiments show, that delaying kinda crashes the program and colours change only after the last delay (in my current case - never, 'cause the loop is neverending). Also, all of the buttons stop working, you can't even close the program. How can I delay some time without disrupting the rest of the program?
If you're using Windows, use Sleep(). the parameter is the delay in milli-seconds.
As I have already mentioned, I tried that. Neither buttons work nor shapes change colours when I use it.
If it is a Windows program, the problem is that Sleep() will block the program's thread, which is also the one containing the message pump. Because you are stuck in Sleep(), the message pump cannot process and dispatch the WM_PAINT or any other Windows notification.

The most straightforward solution would be to do your coloring in a new thread, and then use PostMessage() to post a notification to the main thread that the color of the led changed to some other value. After posting the notification, you can do your Sleep() in your worker thread and repeat as necessary.
But that still wouldn't make buttons accessible, right? Anyway, I'm kinda beginner in C++ and I know nothing about thread programming, which is lame. But I'll be working on it.
Just to make sure, is there any way to delay program without distracting Builder's components?
It WILL make your buttons accessible. The buttons are also controlled by the main thread's message pump. The notifications that your buttons generate, if I remember correctly, are of type WM_COMMAND. The same message pump in charge of redrawing your window pumps the mouse clicks, keystrokes, etc.

If you use a worker thread to orchestrate your led coloring, the main thread will be available to process user input like mouse clicks and system requests like redraws.
Topic archived. No new replies allowed.