Re: Application halts



Ah, I finally found the problem. TTimer isn't accurate enough, as it
actually takes 1001-1010 ms instead of 1000. This means that once in a
while, it will "skip a second" when rounding off to whole seconds.

Example:
6.999 = ~ 7
7.999 + 1.005 = 9.004 = ~ 9
This means that it skips past '8' and if I were to update the time for the
next update at '8' then this update will not take place as it should.

By setting the TTimer to 950 ms, I make sure this doesn't occur. This fixes
the problem for now, as 950 ms is enough. Later I will look into some free
Delphi components that handle time more accurately than TTimer.

Problem solved.

Thanks for your time.

Allan


"John Herbster" <herb-sci1_AT_sbcglobal.net> wrote in message
news:4280a117$1@xxxxxxxxxxxxxxxxxxxxxxxxx
>
> > > (2) How do you accomplish your one second timing?
> > > In particular, do you wait for each part to be accomplished
> > > before starting the next time cycle.
>
> "Allan Nielsen" <ace-allan@xxxxxxxxxxxxxx> wrote
> > I'm just using a TTimer set to 1000 ms. I don't wait for it
> > to accomplish its code, but it should not take more than
> > half a second tops to do what it is supposed to do.
> > Sometimes it runs fine for 20 minutes before stopping.
> > Do you think that this is my problem?
>
> Allan, I think that this could possibly be your problem.
>
> > I could try setting the TTimer.enabled property to false
> > while it is doings its work, and then setting it back to
> > true when it returns from its work. However, this won't
> > give me the kind of accuracy I was hoping for.
>
> OK. So do something like this:
>
> In an initialization section:
> DateTime0 := Now;
> IntervalNbr := 0
> TimerEventNbr := 0;
> IntervalMS := 1000; {milliseconds}
> Timer1.Interval := IntervalMS;
> { Create with enabled = false; set it true here: }
> Timer1.Enabled := true;
>
> procedure TForm1.Timer1Timer(Sender: TObject);
> begin
> Timer1.Enabled := false;
> ... do your one second cycle work here ...
> Inc(TimerEventNbr);
> Repeat
> Inc(IntervalNbr);
> NextInterval := IntervalNbr*IntervalMS/(24*60*60*1000) +
> DateTime0 - Now;
> Until NextInterval > 100; {milliseconds}
> Timer1.Interval := NextInterval;
> Timer1.Enabled := true;
> end; {UNTESTED}
>
> You can compare IntervalNbr and TimerEventNbr
> to see how many cycles you had to skip.
>
> The "NextInterval > 100 milliseconds" check could be
> changed to suit you balance between missed and
> delayed cycles.
>
> Regards, JohnH
>


.