Recent

Author Topic: Timer events and closing form  (Read 3101 times)

swierzbicki

  • Full Member
  • ***
  • Posts: 177
Timer events and closing form
« on: November 05, 2014, 10:06:03 am »
Hello,

I've a simple form with a timer. The timer is checking a network connectivity.
A few labels are updated according to the server connectivity state.

I'm getting "TApplication.HandleException Access violation" when closing my form. I guess (I'm working on a Windows CE project) that my timer event is trying to access freed objects while my form is getting closed.

How can I avoid such situations ? Should I modify my timer event and check all objects like this :

 if assigned(label) then label := 'Blabalbal'; ...

Thank you
Lazarus 1.6.2
fpc 3.0.0
wince/win32/win64
delphi berlin

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Timer events and closing form
« Reply #1 on: November 05, 2014, 10:42:56 am »
Try putting Timer1.Enabled:=false; in the form's onClose event.

swierzbicki

  • Full Member
  • ***
  • Posts: 177
Re: Timer events and closing form
« Reply #2 on: November 05, 2014, 10:48:29 am »
It's already done but I still get access violations.
Lazarus 1.6.2
fpc 3.0.0
wince/win32/win64
delphi berlin

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Timer events and closing form
« Reply #3 on: November 05, 2014, 12:52:52 pm »
So it's WinCE related thing only? Then you can try something different, like public state variable set at beginning and end of timer event. If in the destroy event this state is still true (timer code running), then wait until it turns false.

Code: [Select]
while TimerState do begin
  sleep(1);
  Application.ProcessMessages;
end;

Timer(s) are already disabled before coming to this loop.

 

TinyPortal © 2005-2018