Solved

OnTimeChange

Posted on 2002-03-27
14
461 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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
 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 99
Delphi XE10 Round Image 2 126
HTML text in the body of an email (delphi code) 12 116
Tviruailstringtree sort multi columns on header click 1 62
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 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