Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

alarm

Status
Not open for further replies.

oigo

Programmer
Apr 27, 2002
23
CO
Hello, how can I get that a alarm rises when it gets a time set by the user in minutes, for example, if it is 12:00 o´clok and the user set 20 minutes the alarm rises to 12:20 if set 90 minutes the alarm rises 1:30.
thank you
 
The stuff you want is in the help system under date/time: Go to the entry for, say, the Date function; then click on date/time routines.

Decide what format you are going to use for your times: TDateTime, TTimeStamp, or milliseconds. If your alarms might go across a day boundary, I suggest TDateTime. If they're always within the same day, probably TTimeStamp.

Then convert everything into the format you've chosen, and work with it there:
Code:
var hours,       // number of hours into the future we want the alarm to go off
    mins: Word;  // number of minutes into the future we want the alarm to go off
    alarmtime: TDateTime;  // time we want the alarm to go off
    alarmset: Boolean;
begin
  { add code to get values for hour and min here }
  hours := StrToIntDef(InputBox('hours', 'hours: ', '0'), 0);
  mins := StrToIntDef(InputBox('mins', 'mins: ', '0'), 0);

  alarmtime := Now + EncodeTime(hour, min, 0, 0);
  alarmset := True;
end;
"Now" is a function returning the current date/time. "alarmtime" and "alarmset" need to be global vars; declare them in your form's private section, say.

Now add a TTimer to your form. Add code to its OnTimer event:
Code:
begin
  if alarmset and (Now >= alarmtime) then begin
    ShowMessage('Dingdingdingdingding!')
    alarmset := False;
  end;
end;
If you set the timer active, Delphi will call the OnTimer event once per second (or whatever you set in the Interval). When the current time reaches the alarm time, it'll go off.

Use the debugger to have a look at what values get put into your time variables.

Also take a look at TDateTimePicker, a nifty VCL control. -- Doug Burbidge mailto:doug@ultrazone.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top