[DUG] Ttimer wonderings - and who wants a free widget Analogclock?
John Bird
johnkbird at paradise.net.nz
Mon Jul 24 13:33:51 NZST 2006
The only reason the Application.processmessages is there is to force the
form to redraw after telling it to repaint the form
Form1.Invalidate;
Application.ProcessMessages;
It can sometimes cause a flicker on the screen, which would be nice to
eliminate. It's a sort of safety net, redrawing the form from time to time
as drawing the clock with canvas draws makes it easy for parts of the clock
to go missing if it ever does get covered. Being always on top it doesn't
get covered much, but doing a show desktop (minimising all) will do it.
Update:
I have experimented with instead using the form onpaint event to trigger the
redraw code and that allows me to remove the form1.invalidate and
application.processmessages, and also redraws the screen instantly when
minimised and restored. I am presuming this is a more efficient/cleaner way
of doing it - am I right?.
I notice it gets a small cpu spike (10-15%) for 1 second as it minimises or
restores, but otherwise still shows as using no cpu. And no flicker :).
procedure TForm1.FormPaint(Sender: TObject);
begin
redrawall:=true;
end;
Which causes the next updateclock to call the draw frame (there are a few
other minor tweaks as well).
Let me know if you want the updated source.
John
-----Original Message-----
From: Rohit Gupta [mailto:rohit at cfl.co.nz]
Sent: Monday, 24 July 2006 12:16 p.m.
To: johnkbird at paradise.net.nz; NZ Borland Developers Group - Delphi List
Subject: RE: [DUG] Ttimer wonderings - and who wants a free widget
Analogclock?
John,
I posted this yesterday, but I cant see it so here it goes again.
It runs fine on my PC. However it hiccups every so often in terms of
drawing. I note that Application.ProcessMessages is in there... the most
dangerous feature of Delphi. Its possible that under heavy load the timer
event will be re-entered while execution is already in there.
Try this app with and without the Application.ProcessMessages.
If you must have A.P in your event then you should use a lock such as
an InProgress flag so that do not call the VCL in this manner. Also
note that the single stack stupidity can really stuff things up if
more than one form is involved.
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
public
ReEntry : integer;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
var
I : integer;
begin
inc (ReEntry);
Caption := IntToStr (ReEntry);
Application.ProcessMessages;
for I := 1 to 1100
do begin
Sleep (1);
{ Try it with and without this line}
Application.ProcessMessages;
end;
dec (ReEntry);
Caption := IntToStr (ReEntry);
Application.ProcessMessages;
end;
From: "John Bird" <johnkbird at paradise.net.nz>
To: "'NZ Borland Developers Group - Delphi List'"
<delphi at ns3.123.co.nz>
Subject: RE: [DUG] Ttimer wonderings - and who wants a free
widget Analogclock?
Date sent: Sat, 22 Jul 2006 08:58:04 +1200
Organization: John Bird Consulting
Send reply to: johnkbird at paradise.net.nz,
NZ Borland Developers Group - Delphi List <delphi at ns3.123.co.nz>
<mailto:delphi-request at ns3.123.co.nz?subject=unsubscribe>
<mailto:delphi-request at ns3.123.co.nz?subject=subscribe>
[ Double-click this line for list subscription options ]
Yes it is a standard VCL Ttimer, D2006 Win32. And you could be right, as
far as I know it has never frozen on a few clients PC's that I have tried it
on.
The VCL is usually running on my PC at the same time, and I may indeed have
been doing debugging, even though the program that freezes may have been
started outside the IDE, it does indeed appear to be operating, but just no
longer updating the form/canvas.
John
-----Original Message-----
From: delphi-bounces at ns3.123.co.nz [mailto:delphi-bounces at ns3.123.co.nz] On
Behalf Of Ross Levis
Sent: Friday, 21 July 2006 12:34 p.m.
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Ttimer wonderings - and who wants a free widget
Analogclock?
Have you actually debugged the code to see if the OnTimer procedure is
not being executed?
I've never had a timer freeze before. My audio player relies on a 50ms
loop which runs continuously. If this stopped, it would fail to load
the next track, and no one has ever complained of that. I have several
users running Windows 98, but most are using XP.
What I have experienced, however, is my graphical VU (volume) meter
freeze. This is on the same timer as everything else so the timer
doesn't stop, but the VU meter can suddenly stop painting for some
reason. This has only occured once on my development PC, and many times
on another PC which I access via Remote Desktop Connection.
I was debugging at the time it occured on my PC. The code appeared to
be executed correctly, with canvas draws, but nothing changing on the
screen. Just wo9ndering if you are perhaps experiencing a similar
problem.
Ross.
----- Original Message -----
From: "John Bird" <johnkbird at paradise.net.nz>
To: "'NZ Borland Developers Group - Delphi List'" <delphi at ns3.123.co.nz>
Sent: Friday, July 21, 2006 10:45 AM
Subject: RE: [DUG] Ttimer wonderings - and who wants a free widget
Analogclock?
I have two programs with long running timers, and both tending to
freeze,
after some hours. And not at the same time.
One is a menu dispatcher program which just puts the current date and
time
into a text label every second. The programs attempts to disable and
re-enable the timer do NOT work even though the rest of the program
does -
it stays frozen, ie the timer is no longer working at all.
The other is a quite cool widget clock.
Either of them prone to freezing.
Maybe its my system. I have the Windows XP Power toys task switcher
installed (gives a small screen shot of each task as you Alt/Tab through
them, but its always been rather buggy). That is often showing as the
dominant task when one of the clocks freezes (Thanks to Process
Explorer -
well actually process explorer is the other candidate....).
The clock has a bit more in its timer loop, but not that much....20-30
lines
of code, mainly just simple calculation and canvas draw.
Would anyone else like to test the widget clock on their system to see
if
its just here?
A bit about it:
-Part of a suite of time management tools, but stand alone free
giveaway -
source too if interested.
-Did it to tech myself a bit of graphics and fancy type windows
-inconspicuous on the system ie 399K and has never shown as using any
CPU.
-Inconspicuous floating desktop clock - Mixture of transparent form and
alphablend and always on top makes it look just like one of the Max OSX
or
Vista widgets/gadgets, can be dragged by the roundframe (the rest is
transparent)
-Based on the look of one of the Opera transparent widget clocks, but
also
with seconds and date. The Opera one only runs while the browser is
open.
Email me if you would like a free copy to test - any comments welcome as
well.
John
_______________________________________________
Delphi mailing list
Delphi at ns3.123.co.nz http://ns3.123.co.nz/mailman/listinfo/delphi
_______________________________________________
Delphi mailing list
Delphi at ns3.123.co.nz http://ns3.123.co.nz/mailman/listinfo/delphi
__________ NOD32 1.1461 (20060329) Information __________
This message was checked by NOD32 antivirus system. http://www.eset.com
_______________________________________________
Delphi mailing list
Delphi at ns3.123.co.nz http://ns3.123.co.nz/mailman/listinfo/delphi
Regards
Rohit
======================================================================
CFL - Computer Fanatics Ltd. 21 Barry's Point Road, AKL, New Zealand
PH (649) 489-2280
FX (649) 489-2290
email rohit at cfl.co.nz or r.gupta at xtra.co.nz
======================================================================
__________ NOD32 1.1461 (20060329) Information __________
This message was checked by NOD32 antivirus system. http://www.eset.com
More information about the Delphi
mailing list