0

I have a simple VCL form with a TAnimate component set to use the aviCopyFiles. The form includes the ShellAnimations unit so it works on Windows 7.

On form activate, it makes the TAnimate active then starts copying files using LZCopy as part of an update process.

What I am finding though is that the TAnimate image only changes if when I call Application.ProcessMessages, even though it is supposed to be in it's own thread (Timers property is false).

How do I get it to be smoothly animated while in the loop to copy the updated files?

TLama
  • 75,147
  • 17
  • 214
  • 392
SiBrit
  • 1,460
  • 12
  • 39

1 Answers1

4

Change your mind!

The main thread of the application is meant to maintain the UI and to be responsive to the Operating System, for example, servicing the message queue and responding appropriately to the received messages.

Thinking that way, you will realize that you don't need a TAnimate that works while your main thread is busy. What you need is to have a responsive main thread by moving the heavy work to a different thread.

In your case, moving your loop to copy the updated files to a different thread, you'll get the TAnimate smoothly animated all the time by the main thread.

Ken White
  • 123,280
  • 14
  • 225
  • 444
jachguate
  • 16,976
  • 3
  • 57
  • 98
  • There is nothing else for the main thread to do while this copy process is happening. The user cannot and should not be doing anything else with the application. The form is shown modal. Why go through all the hassle of threading just to get a stupid TAnimate to work when the docs specifically say "When Timers is false, the animation is played in a separate thread.". This implies to me that even if the main thread is busy in a loop, the animation should still happen. This is not the case. – SiBrit Jun 05 '13 at 02:25
  • Of course there it is something else to the main thread, and is to maintain the responsiveness of the application to the host operating system and the UI. Maybe you don't like it, but is the way the windows programming should be done. – jachguate Jun 10 '13 at 23:55
  • Just posting a comment here to say that yes, I should have had the main thread start a new thread that does the copy process while the main thread just refreshes the graphic and handles OS messages. Unfortunately i was stuck for time and needed a simple solution where the main thread did the copy process and just wanted a visual clue as to progress. – SiBrit Sep 19 '16 at 04:00