Lazarus

Programming => LCL => Topic started by: xamsin on September 02, 2012, 08:11:36 pm

Title: I don't understand TIdleTimer using
Post by: xamsin on September 02, 2012, 08:11:36 pm
Hallow. Could anybody tell me about using of this stupid >:( component.   
I not understand about propertis FireOnIdle? AutoEnabled? (AutoStartEvent? and AutoEndEvent?
what about thay values, what are thay meen. (itaOnUserInput,itaOnIdleEnd,itaOnIdle)).
May be some examples usind TIdleTimer. (I not found this in forum or lasarus wiki, it's a problem of Lazarus not enougth Documentation for dummies  :( ).
Title: Re: I don't understand TIdleTimer using
Post by: typo on September 02, 2012, 10:23:26 pm
Stupid component? Dummies should have a little more respect.

http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/tidletimer.html
Title: Re: I don't understand TIdleTimer using
Post by: eny on September 02, 2012, 11:22:50 pm
Hallow. Could anybody tell me about using of this stupid >:( component.
Ah you must be a relative of Anna.
http://www.lazarus.freepascal.org/index.php/topic,18056.msg101287.html#msg101287
Title: Re: I don't understand TIdleTimer using
Post by: Leledumbo on September 02, 2012, 11:58:04 pm
Quote
(I not found this in forum or lasarus wiki, it's a problem of Lazarus not enougth Documentation for dummies   ).
At least not for this component, as typo has pointed out. You can also press F1 on it (assuming you're using at least latest 1.0 version).
Title: Re: I don't understand TIdleTimer using
Post by: typo on September 03, 2012, 02:12:19 am
We do not owe you anything. If Lazarus is useful to you, you are welcome. If not, simply don't use it.
Title: Re: I don't understand TIdleTimer using
Post by: xamsin on September 03, 2012, 05:01:27 am
Hi, typo. Could you post some examples using this component.
 i have read little about this component here http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/tidletimer.html before i asking my question.
so if I wrote
 AutoEnabled:=true;
and
 procedure TForm1.IdleTimer1StopTimer(Sender: TObject);
 begin
  form1.Close;
 end;
 My form closes on start! AutoStartEvent=itaonidle, AutoEndEvent=itaonIdleEnd
 If I set FireOnIdle:=true; Timer never stop't.
 
 ????? So may be some examles.....
 
Title: Re: I don't understand TIdleTimer using
Post by: typo on September 03, 2012, 12:46:28 pm
Quote
it's a problem of Lazarus not enougth Documentation.
How about you post some documentation?

Quote
????? So may be some examles.....
How about you post some example?

Title: Re: I don't understand TIdleTimer using
Post by: Blaazen on September 03, 2012, 01:32:21 pm
Well, when TIdleTimer.AutoEnabled=False then it behaves just like normal TTimer.
If you switch to Enabled:=False and AutoEnabled:=True then (in default configuration, i.e. AutoStartEvent=itaOnIdle and AutoEndEvent=itaOnUserInput) this timer raises events on IDLE (= when nothing happens, i.e. you don't move move, no clicks, no keyboard input etc.)

I attached a small app. to testing. It is very easy, you can do it yourself too, it takes a few minutes to create such app.
Title: Re: I don't understand TIdleTimer using
Post by: ludob on September 03, 2012, 01:50:14 pm
Drop a TIdleTimer and a label on a form. Set TIdleTimer.AutoEnabled to true and Interval to 5000.  Add following code:
Code: [Select]
procedure TForm1.IdleTimer1StartTimer(Sender: TObject);
begin
label1.caption:='start';
end;

procedure TForm1.IdleTimer1StopTimer(Sender: TObject);
begin
label1.caption:='stop';
end;

procedure TForm1.IdleTimer1Timer(Sender: TObject);
begin
label1.caption:='event';
end;
and you'll see immediately what it is all about. Much quicker than writing a post complaining about lack of documentation / examples and it exercises the brain a little in the same time.

As the name says TIdleTimer is a timer that runs when the app is idle. OnStartTimer is triggered by default when the app is idle (itaOnIdle) and the timer starts, OnStopTimer when the app detects user input (itaOnUserInput) and consequently stops  8-)  When you leave the app idle for Interval millisecs OnTimer is triggered which is identical to TTimer. I'll let you guess what the different AutoEndEvent/AutoEndEvent settings are. Hint: idle refers to the state of the app, not the timer ;D

So setting form1.Close in OnStopTimer means (ifAutoEndEvent=itaonIdleEnd) that you close the form as soon as the app has been idle (event queue empty) and a new event comes in which is very frequent.
Title: Re: I don't understand TIdleTimer using
Post by: BigChimp on September 03, 2012, 06:30:55 pm
Perhaps the OP would like to donate some of the time the others' responses saves him by writing a wiki article on TIdleTimer (in English or his own language) so dummies that need documentation for this stupid component can find it...
Title: Re: I don't understand TIdleTimer using
Post by: rc.1990 on September 27, 2016, 07:49:04 am
First, my condolences for BigChimp and thanks to all help he provided.

Studying this thread, I have made a small projet to learn how TIdleTimer works.
The OnStopTimer and OnTimer events are working as expected, but the OnStartTimer event keeps firing as soon as either OnStopTimer or OnTimer events are fired and not after I stoped using Mouse or Keyboard input and computer becoming really idle.

Is this the expected behavior for OnStartTimer event? Shouldn't Label1 keeping "stop" until computer becoming idle and then Label1 been changed to "start" counting time until next OnTimer event to be fired?

My small project for testing is attached.

Code: Pascal  [Select][+][-]
  1. unit unit2;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   ExtCtrls;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Edit1: TEdit;
  17.     IdleTimer1: TIdleTimer;
  18.     Label1: TLabel;
  19.     Label2: TLabel;
  20.     procedure FormCreate(Sender: TObject);
  21.     procedure IdleTimer1StartTimer(Sender: TObject);
  22.     procedure IdleTimer1StopTimer(Sender: TObject);
  23.     procedure IdleTimer1Timer(Sender: TObject);
  24.   private
  25.     { private declarations }
  26.   public
  27.     { public declarations }
  28.   end;
  29.  
  30. var
  31.   Form1: TForm1;
  32.  
  33. implementation
  34.  
  35. {$R *.lfm}
  36.  
  37. { TForm1 }
  38.  
  39. procedure TForm1.FormCreate(Sender: TObject);
  40. begin
  41.   IdleTimer1.AutoEnabled := True;
  42.   IdleTimer1.AutoStartEvent := itaOnIdle;
  43.   IdleTimer1.AutoEndEvent := itaOnUserInput;
  44.   IdleTimer1.Interval := 3000;
  45.   IdleTimer1.Enabled := False;
  46. end;
  47.  
  48. procedure TForm1.IdleTimer1StartTimer(Sender: TObject);
  49. begin
  50.     label1.caption:='start';
  51. end;
  52.  
  53. procedure TForm1.IdleTimer1StopTimer(Sender: TObject);
  54. begin
  55.     label1.caption:='stop';
  56.     label2.caption:='stop';
  57. end;
  58.  
  59. procedure TForm1.IdleTimer1Timer(Sender: TObject);
  60. begin
  61.     label1.caption:='event';
  62.     label2.caption:='';
  63. end;
  64.  
  65. end.
  66.  
Title: Re: I don't understand TIdleTimer using
Post by: molly on September 27, 2016, 03:55:50 pm
As far as i am able to see from writing the events in a memo

- Having AutoEnabled active means that the AutoStartEvent and AtoEndEvent properties takes care of 'activating' or 'stopping' the timer.
- The timer is enabled (e.g. starts counting) when idle is encountered (in case you have itaOnIdle as the AutoStartEvent)
- It 'stops' counting when the AutoEndEvent is encountered (in your case itaOnUserInput) and will not 'activate' the timer but only starts counting again until things become idle (itaOnIdle) again.

This process is a continues process, because the moment you stop providing userinput the itaOnIdle comes into play again, which 'enables' the timer, counts down and fires the timer event with the provided interval.

So, whenever the StartTimer event fires, you can be certain that things are "idle". The timer is enabled and starts counting. If in between you start giving user input again, the counting is interrupted and the timer event will not fire.

Conclusion: afaik this is the expected behaviour.
Title: Re: I don't understand TIdleTimer using
Post by: rc.1990 on September 27, 2016, 04:05:44 pm
Thanks molly.
Title: Re: I don't understand TIdleTimer using
Post by: howardpc on September 27, 2016, 07:03:55 pm
The attached project lets you explore the properties and events of TIdleTimer further.
Title: Re: I don't understand TIdleTimer using
Post by: totya on September 29, 2016, 07:47:11 pm
Hi!

My question is, what is the suggested method order in the beginning of the OnTimer event?

Code: Pascal  [Select][+][-]
  1. AutoEnabled:=False;
  2. Enabled:=false;

or

Code: Pascal  [Select][+][-]
  1. Enabled:=false;
  2. AutoEnabled:=False;
Title: Re: I don't understand TIdleTimer using
Post by: howardpc on September 30, 2016, 12:16:26 pm
I can't see that the order of setting these properties to False makes the slightest difference to subsequent behaviour.
Title: Re: I don't understand TIdleTimer using
Post by: totya on October 08, 2016, 12:58:59 am
Hi!

Thanks for the answer!
Title: Re: I don't understand TIdleTimer using
Post by: rc.1990 on August 03, 2018, 01:41:23 pm
hello,
for your idle timer why do you not use the component tidletimer ( system components tab) ?
Blaazen in another post explains what is it :
Quote
Well, when TIdleTimer.AutoEnabled=False then it behaves just like normal TTimer.
If you switch to Enabled:=False and AutoEnabled:=True then (in default configuration, i.e. AutoStartEvent=itaOnIdle and AutoEndEvent=itaOnUserInput) this timer raises events on IDLE (= when nothing happens, i.e. you don't move move, no clicks, no keyboard input etc.)

so, to use this component in a form for no activity detection, for example put a tidletimer in your form with properties :
AutoEnabled :  True
AutoEndEvent :  itaOnUserInput
AutoStartEvent : itaOnIdle
Enabled : False
Interval : 60000

and for OnTimerEvent this procedure :
Code: [Select]
procedure TForm1.IdleTimer1Timer(Sender: TObject);
begin
  showmessage('no activity during one minut');
end;   

Friendly, J.P
Thanks all. Solved:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   IdleTimer1.AutoEnabled:=True;
  4.   IdleTimer1.AutoEndEvent:=itaOnUserInput;
  5.   IdleTimer1.AutoStartEvent:=itaOnIdle;
  6.   IdleTimer1.Enabled:=False;
  7.   IdleTimer1.Interval:=5000;
  8. end;
  9.  
  10. procedure TForm1.IdleTimer1Timer(Sender: TObject);
  11. begin
  12.   ShowMessage('Application will be closed by inactivity.');
  13.   Application.Terminate;
  14. end;
Title: Re: I don't understand TIdleTimer using
Post by: dbannon on August 03, 2018, 02:03:33 pm
Well Done !
That looks like a great example to add to -
http://wiki.freepascal.org/TIdleTimer

 :D
Davo
Title: Re: I don't understand TIdleTimer using
Post by: jerrylaz on November 21, 2020, 04:19:08 pm
I have attached a small program for testing out the TIdleTimer.
The program consist of a loop which can be turn ON or OFF. It is used to make the program to appear busy when turned ON.
You can change the properties of the TIdleTimer on the fly and see how its OnStartTimer/OnStopTimer/OnTimer events behave.
Depending on the AutoStartEvent and AutoEndEvent mode, the OnStartTimer and OnStopTimer events can fire hundreds of times every second.
When the AutoStartEvent condition is met, it will auto turn on the timer and the OnTimer event will fire after the interval set and the OnTimer event will repeats itself until the AutoEndEvent condition has been met.

AutoStartEvent and AutoEndEvent works only if AutoEnabled is true.
When AutoEnabled is false, TIdleTimer works exactly like a normal TTimer.
TinyPortal © 2005-2018