Have a private variable busy
Public
Busy : Boolean;
End.
Then on the oncreate have
Procedure OnCreate(Sender : TObject);
Begin
Busy :=False;
End;
Then on the timer
Procedure Tick(Sender : TObject);
Begin
If Busy then
BusyPanel.color := clRed
Else
BusyPanel.color := clGreen;
End;
Then on your busy code
Begin
..
..
Busy:=True;
//Do your thing here
..
..
Busy:=False;
End;
U must make sure tho that your busy code refreshes the screen either thru
application.processmessages or self.update and the timer should tick maybe
ever 500 milliseconds
A neater and better way would be to thread your busy process then when the
thread is over it sets the status bar back to green - would be more elegant
plus wont "hang" your forms. But then again threading has its own issues
depending on what your busy code is doing...
Chris Albert,
Innovative Technologies.
http://www.it.co.ke/beta
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf
Of kc0fcp
Sent: Wednesday, August 10, 2005 10:07 PM
To: [email protected]
Subject: [delphi-en] How to use TTimer as a busy function with timeout?
I am trying to create a busy status indicator for a communication
process. When data is incoming, events occur at least every 1.3
seconds. Events can occur at intervals shorter than 1.3 seconds, if
the messages are short.
I want to set a busy status on the incoming data event, and then have
a TTimer turn the busy status off again if 1.4 seconds elapses without
any incoming data events. (It is OK if it remains busy a bit longer
than the actual duration)
I tried creating SetBusy and ClearBusy procedures like this:
procedure TForm1.SetBusyIndicator;
begin
Timer1.enabled := True;
BusyPanel.color := clRed;
end;
procedure TForm1.ClearBusyIndicator(Sender: TObject);
begin
Timer1.enabled := False;
BusyPanel.color := clBtnFace;
end;
SetBusyIndicator is called by the incoming event handler.
ClearBusyIndicator is the OnTimer event for Timer1.
When the input is busy for 5 events (about 6.5 seconds) the busy
indicator goes on and off with alternating events, rather than staying
continually set for 7.8 seconds as expected.
I have been unable to find a good explanation for how TTimers work.
>From reading the TTimer source in ExtCtrls, I thought that enabling
the timer resets the count and restarts the timer.
I want the SetBusy procedure to restart the timer, so the busy status
will remain set for 1.4 seconds after the last SetBusy event.
Does anyone know how this could be accomplished?
Thanks,
Tim.
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
------------------------ Yahoo! Groups Sponsor --------------------~-->
<font face=arial size=-1><a
href="http://us.ard.yahoo.com/SIG=12hlf2uq3/M=362131.6882499.7825260.1510227/D=groups/S=1705115362:TM/Y=YAHOO/EXP=1123708403/A=2889191/R=0/SIG=10r90krvo/*http://www.thebeehive.org
">Get Bzzzy! (real tools to help you find a job) Welcome to the Sweet Life
- brought to you by One Economy</a>.</font>
--------------------------------------------------------------------~->
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/