Recent

Author Topic: I don't understand TIdleTimer using  (Read 20191 times)

xamsin

  • New member
  • *
  • Posts: 9
I don't understand TIdleTimer using
« 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  :( ).
« Last Edit: September 02, 2012, 08:21:43 pm by xamsin »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: I don't understand TIdleTimer using
« Reply #1 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

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: I don't understand TIdleTimer using
« Reply #2 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
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: I don't understand TIdleTimer using
« Reply #3 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).

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: I don't understand TIdleTimer using
« Reply #4 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.

xamsin

  • New member
  • *
  • Posts: 9
Re: I don't understand TIdleTimer using
« Reply #5 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.....
 

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: I don't understand TIdleTimer using
« Reply #6 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?


Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: I don't understand TIdleTimer using
« Reply #7 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.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: I don't understand TIdleTimer using
« Reply #8 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.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: I don't understand TIdleTimer using
« Reply #9 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...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

rc.1990

  • Jr. Member
  • **
  • Posts: 54
Re: I don't understand TIdleTimer using
« Reply #10 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.  

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: I don't understand TIdleTimer using
« Reply #11 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.

rc.1990

  • Jr. Member
  • **
  • Posts: 54
Re: I don't understand TIdleTimer using
« Reply #12 on: September 27, 2016, 04:05:44 pm »
Thanks molly.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: I don't understand TIdleTimer using
« Reply #13 on: September 27, 2016, 07:03:55 pm »
The attached project lets you explore the properties and events of TIdleTimer further.

totya

  • Hero Member
  • *****
  • Posts: 720
Re: I don't understand TIdleTimer using
« Reply #14 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;

 

TinyPortal © 2005-2018