Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Extremely weird behavior with Now function (D6)

0 views
Skip to first unread message

Tommi Prami

unread,
Mar 19, 2008, 3:27:03 AM3/19/08
to
Hello,


I have following debug code on app It seemed that I was not able to
track processing time. This code and it's "surroundings" are called from
TTimer with 5000 msec interval,

LNow := Now;
if FNow <> 0 then
begin
LTimeDiff := LNow - FNow;
end;
FNow := LNow;


What is puzzling here that LNow gets same value every single time, if I
debug into Now function there will be correct value, it least it seems
to change trough time (I will investigate this a little bit more), what
can change the value??? And before this Debug code I did pass value
directly from Now function tu the MilliSecondsBetween or MilliSecondSpan
functions with same behavior???

Any ideas on this???

-Tommi Prami-

Tommi Prami

unread,
Mar 19, 2008, 4:21:57 AM3/19/08
to
Littlebit more info

Now looks like this,
var
SystemTime: TSystemTime;
begin
GetLocalTime(SystemTime);
with SystemTime do
Result := EncodeDate(wYear, wMonth, wDay) +
EncodeTime(wHour, wMinute, wSecond, wMilliseconds);
end;


In EncodeTime value after decimal separator is quite diferent what is
Result in Now before leaving the Function.

Smeens that the what problem I see happens before value is passed to my
code.

Does anyone has any ideas how to proceed. I've deleted all DCU's
compiled by project. Used vatious different compiler parameters, every
time same result...

I am completely lost here, Now functions seems to work just fine in some
other parts of the program, be cause when process (which passing I am
tying to visualise to screen) ends End time is written to property of an
object and when that value is used it program shows exact �time passed
between sart time and end time. And putting the process start time to
variable works also :)

Any ideas where to look at this...

-TP-

Wayne Niddery (TeamB)

unread,
Mar 19, 2008, 11:36:52 AM3/19/08
to
"Tommi Prami" <tommi.nos...@poista.ecomond.com> wrote in message
news:47e0cd25$1...@newsgroups.borland.com...

> I am completely lost here, Now functions seems to work just fine in some
> other parts of the program, be cause when process (which passing I am
> tying to visualise to screen) ends End time is written to property of an
> object and when that value is used it program shows exact ´time passed
> between sart time and end time. And putting the process start time to
> variable works also :)


In the unit you are having trouble, or in any unit it uses, look for another
variable or function method named Now. There is simply no way that the
built-in Now function is going to return the same value after 5 seconds.

The only other thing I can think of is if LNow is a property with a setter
method and that method is overriding the assignment.

I note that LTimeDiff, give or take a few due to the low priority of timer
messages, is always going to calculate to 5000 ms or whatever you set the
timer interval to.

--
Wayne Niddery - TeamB (www.teamb.com)
Winwright, Inc. (www.winwright.ca)

Tommi Prami

unread,
Mar 20, 2008, 2:57:14 AM3/20/08
to
Hello,

FNow was private variable, not an property, LNow is just an Local variable.

LTimeDiff was just to debuggig only, because it was easyer to check that
than compare two floating point values.

I debugged the code and stepped into Now function and it's result was
Wrong _BEFORE_ debugger left function.

Time part was correct (or seemed so) at EncodeTime(), and _Frac part was
clearly different_ at EncodeTime than in Now after EncodeDate() +
EncodeTime()

This is more than mysterious.

I have workaround which obviously don't work at midnight,

MilliSecondSpan(Frac(LConnectionInfoItem.JobStartTime), Frac(Time))

Which uses EncodeTime internally if I recall. I'll boot up my
developement machine and check again with older code, to see if Now
works at it's mysterious ways today :D

-TP-

John Herbster

unread,
Mar 20, 2008, 8:43:10 AM3/20/08
to

"Tommi Prami" <tommi.nos...@poista.ecomond.com> wrote

> I have following debug code on app It seemed that I was not able to
> track processing time. This code and it's "surroundings" are called from
> TTimer with 5000 msec interval,
> LNow := Now;
> ...
> What is puzzling here that LNow gets same value every single time,
> ...
> Any ideas on this?

Tommi,

Is your TTimer.OnTimer event reentrant? In other words, have you prevented processing another OnTimer event while one OnTimer event is being processed? Here is one way to do this:

procedure TForm1.Timer1Timer(Sender: TObject);
var LNow: TDateTime;
begin
(Sender as TTimer).Enabled := false;
Try{Finally}
<do interval work>
Finally
(Sender as TTimer).Enabled := true;
End;
end;

HTH, JohnH

Tommi Prami

unread,
Mar 20, 2008, 9:56:11 AM3/20/08
to
Ok,

Now works differently today :)

Now it will give more than less random values, not always exactly same...

I'll try once more...

Debug code now is (comment gives you value of variable after each row
LTimeValue := Time; // 0.58125936985
LDateValue := Trunc(Date); // 39527
LDtValue := LDateValue + LTimeValue; // 39527.582031

Ok... I'll try someting else...

Found it!!! Finally...

This was more than interesting... There was an optimization in this
program (remembered it vaguely) which sets 8087 precision to ptSingle,
and this caused the Time values "round" to weird values :)

If I didn't have tested this before, (trying to optimize on different
program) and then Single precision mad eprogman unUsable when some
datetime values just did not work. Some comparation was not working
anymore or similar...

I thank the viewing audience and mostly one that participated in this
endeavor of mystic behavior or my code :D

-TP-


0 new messages