Search code examples
delphiwindows-7timerdelphi-7

TTimer not firing


I'm having a strange problem. I have a TTimer on my main form that should trig 500 msec. after the form is created.

It works fine when I run it from IDE, but when I run it on other W7 PC's the main form is created, but the timer doesn't fire. (Some components are not updated) If I click a control, everything is updated and the timer fires and every thing is fine. If I move the form, every thing is updated but timers are not started. If I run it on PC with Delphi installed, it works fine. No problem.

Code in MyForm.OnCreate is executed fine. Timer.Enabled := True makes no change.

Any idea what causes this? I'm really stuck here.

Best regards.


Solution

  • There are a variety of possibilities:

    1. WM_TIMER messages are only delivered when your message queue is empty. If something in your app, or something in another app running on those other computers was posting messages to the window handle frequently enough that the message queue for that window never empties, WM_TIMER events would never fire. If this was happening, you might have to wait 10x or 20x or 30x the normal TTimer period but the event would probably fire, eventually. I have not observed any situation so far gone that the timer doesn't fire at all, but that is of course, theoretically possible...

    2. Although you say you know for sure that the timer is Enabled (you set it enabled) it is possible that somewhere ELSE in your code you're disabling it.

    3. If you were doing some try...except..end blocks and ignoring an exception then something bad might be happening that you don't see on those other machines.

    4. Your timer code might be firing, but an exception, crash or hang might be happening in the code that runs on the timer.

    5. You might have, in your code, some series of Delphi event handlers which create a nearly "endless loop" situation because some event handlers you've written are firing when you don't want them to, causing side effects, which are keeping your application busy. You mention that you're clicking somewhere and the problem goes away. That click might be enough to interrupt some other vicious cycle in your code.

    6. You mention that it works on any PC with delphi installed on it. Are you using a third party control that has some limitations in it (like requiring that you run inside the debugger?). Or does your app load some DLLs or BPLs that are not installed on those other computers?

    Start with a brand new application that has nothing in it. Add a TTimer. Now on the timer event increment an integer field value and write that value to a caption of the form. Now run it on the other machines. It will work fine.

    Now go look at the giant pile of code you wrote, and decide how to bisect your giant pile of code to find the half that is broken. After enough steps, you will find your problem. Nobody here can debug it for you.

    Try adding some logging messages, using OutputDebugString and run DebugView on the other machines, if you want to see some internals of your application, on that other machine