Recent

Author Topic: Disable Timer within the OnTimer Event  (Read 3947 times)

JimKueneman

  • Full Member
  • ***
  • Posts: 246
Disable Timer within the OnTimer Event
« on: January 11, 2013, 06:33:32 pm »
I commonly disable a timer from within the OnTimer Event.. typically for one shot event type things.  I am now trying to use it as a "lazy" load so when I load something in to a staging list I enable the TTimer.  In the event handler I disable it, until another item(s) is added to the staging list starting the process over.

In Win32 XP (have not tried other Win OS) this work fine ... for the first loop.  Once the timer is disabled in the event handler Windows seems to be broken for that event handler.  I have traces the code into the LCL and the new timer is being creating with a valid handle, the LCL is creating the stub so it can find it in the callback, other timers work fine, but that timer is never callback in the API again.

I run it in OSX Lion and it works just fine.

Anyone seen this before?

Jim

Bart

  • Hero Member
  • *****
  • Posts: 5706
    • Bart en Mariska's Webstek
Re: Disable Timer within the OnTimer Event
« Reply #1 on: January 12, 2013, 01:04:08 pm »
This works fine for me on Win7 (Lazarus 1.1/fpc 2.6.2RC1)

Code: [Select]
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  writeln('OnTimer');
  if checkbox1.checked then
  begin
    timer1.Enabled := false;
    writeln('Disabling timer1');
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 if not timer1.Enabled then
 begin
   writeln('Enabling Timer1');
   timer1.Enabled := true;
 end;
end;

Running:

Code: [Select]
C:\Users\Bart\LazarusProjecten>test
OnTimer
OnTimer
OnTimer
OnTimer
//checked the checkbox
Disabling timer1
//unchecked the checbox, then clicked button1
Enabling Timer1
OnTimer
OnTimer

Bart

 

TinyPortal © 2005-2018