Solved

OnTimeChange

Posted on 2002-03-27
14
458 Views
Last Modified: 2007-12-19
How can I intercept a system time change to get the difference occured?
0
Comment
Question by:cosminm
  • 6
  • 3
  • 3
  • +2
14 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 6901173
1. create your time-change monitor as a service
2. look at the call-back API documentation for the time change message.
0
 
LVL 1

Expert Comment

by:Summa
ID: 6902152
from Windows-SDK-Help

An application sends the WM_TIMECHANGE message to all top-level windows after changing the system time

0
 
LVL 45

Expert Comment

by:aikimark
ID: 6902507
You will need to capture the system time on a regular basis in order to compare for the changed time difference calculation.
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6902892
type
  TForm1 = class(TForm)
  private
    procedure Timechanged(var msg:TMessage);message WM_TIMECHANGE;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Timechanged(var msg: TMessage);
begin
    showmessage('Time Changed');
end;
0
 

Author Comment

by:cosminm
ID: 6903648
Nice example DrDelphi for capturing the message, but I need to obtain the difference time ocured at the time change moment. Any ideas or examples, please...
Aikimark, do u have an example?
0
 
LVL 6

Accepted Solution

by:
DrDelphi earned 150 total points
ID: 6903668
The only solution that seems workable is to have a timer which does nothing but update a global variable with the current time.Then compare that variable to the new time in the message handler. For example:

type
 TForm1 = class(TForm)
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
 private
   procedure Timechanged(var msg:TMessage);message WM_TIMECHANGE;
   { Private declarations }
 public
    Currenttime:TDateTime;
   { Public declarations }
 end;

var
 Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.Timechanged(var msg: TMessage);
var oldTime,newTime:string;
begin
   OldTime:=TimeToStr(CurrentTime);
   newTime:=TimeTostr(now);
   ShowMessage(OldTime+#13+Newtime);
   end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  CurrentTime:=now;
end;

0
 

Author Comment

by:cosminm
ID: 6903687
The example is wrong because the difference is padded with timer interval...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 45

Expert Comment

by:aikimark
ID: 6903755
this might get a little tricky.  You have to check for a time-change message when the timer pops.  I'd recommend two time variables (or two item array).  This should accomodate the possible collision between a timer event and the time change message.

Depending on the circumstance, you might have to create a timer using a Win API (callback), if you are going to do this as a (formless) service.
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6906366
Use GetTickCount which gives the number of tics since the system started, 'not' the time of day.
Get the tick count on WM_TIMECHANGE subtract
the earlier tickcount from the just triggered count and you have the difference.

Regards,
Steve
0
 

Author Comment

by:cosminm
ID: 6906726
SteveWaite, seems to be an excelent solution...
But you have an example with GetTickCount (i haven't used before)...
And u'll get the points...
0
 

Author Comment

by:cosminm
ID: 6906808
Whops, is not a good solution 'cause the GetTickCount expire after about 50 days on Win9x and over that the function is not influenced by time changing... so no substract possible.
Waiting for another solution...
0
 

Author Comment

by:cosminm
ID: 6907005
Seems to be not other solution than the one with a global variable...
Thanks guys anyway...
DrDelphi u've got the points...
0
 

Author Comment

by:cosminm
ID: 6907866
Bug or what?! On WinNT-2000 all platforms works perfect the WM_TIMECHANGE event but on Win9x doesn't respond on system change! Or sometimes happens to capture the event twice!
What's happening? Please!
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6909543
cheers
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now