-1

im trying to fire a notification in specific time using TimeEdit, it didnt work! the code i used..

try
MyNot.Name := Edit1.Text;
MyNot.AlertBody := Edit2.Text;
MyNot.FireDate := Now + TimeEdit1.Time;
NotificationCenter1.ScheduleNotification(MyNot);
Finally
MyNot.DisposeOf;

im using Delphi10 Seattle Update1.

ColdZer0
  • 233
  • 1
  • 4
  • 19
  • http://docwiki.embarcadero.com/RADStudio/Seattle/en/Using_Notifications#Creating_Notifications – kami Mar 24 '16 at 11:11
  • nothing about TimeEdit buddy @kami – ColdZer0 Mar 24 '16 at 11:35
  • 1
    Don't think about TTimeEdit. I think, your problem not in this control. Try to use `myNot.FireDate:=IncSecond(Now, 30);` for example – kami Mar 24 '16 at 12:03
  • it works using InSecond, but i cant fire notification using the TimeEdit! @kami – ColdZer0 Mar 24 '16 at 12:06
  • What value you pass to TimeEdit? – kami Mar 24 '16 at 12:11
  • `MyNot.FireDate := Now + TimeEdit1.Time;` @kami – ColdZer0 Mar 24 '16 at 13:14
  • I see this. I mean value inside `TimeEdit1`. Something like `00:05:00`. Value, that user enter into this control. – kami Mar 24 '16 at 13:21
  • @kami: And what is that supposed to represent to your app exactly? `TTimeEdit` represents an absolute time of day. You are adding that to the current clock timestamp. So, do you want the notification to fire 5 minutes after the current date/time, or do you want it to fire at exactly 12:05am of the current date? Those are two completely different things. So what are you really trying to accomplish? If you want to fire at a *specific* time of a *specific* date, look at functions like `EncodeDateTime()`, `ReplaceTime()`, etc. – Remy Lebeau Mar 24 '16 at 16:20
  • @RemyLebeau this is not my app :) I also think that OP want enter absolute time, but this code works with relative. – kami Mar 24 '16 at 16:48

1 Answers1

0

Now() returns a TDateTime that represents the current clock date/time. You are then adding the user's entered time relative to the current date/time. For example, if the user enters 00:05:00, you will be adding 5 minutes to the current date/time.

If you want the notification to fire at a specific time of the current date, use the Date() function instead of the Now() function so that you are adding the entered time relative to midnight (00:00:00am):

MyNot.FireDate := Date + TimeEdit1.Time;

Alternatively, you can use the SysUtils.ReplaceTime() function instead:

var
  dt: TDateTime;

dt := Date;
ReplaceTime(dt, TimeEdit1.Time);
MyNot.FireDate := dt;

This has the additional benefit that you can then configure whatever date you want, such as from the SysUtils.EncodeDate() function:

var
  wYear, wMonth, wDay: Word;
  dt: TDateTime;

wYear := ...;
wMonth := ...;
wDay := ...;
dt := EncodeDate(wYear, wMonth, wDay) + TimeEdit1.Time;
MyNot.FireDate := dt;

Or:

var
  wYear, wMonth, wDay: Word;
  dt: TDateTime;

wYear := ...;
wMonth := ...;
wDay := ...;
dt := EncodeDate(wYear, wMonth, wDay);
ReplaceTime(dt, TimeEdit1.Time);
MyNot.FireDate := dt;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Many Thanks mate,Perfect. Please can You check my other post [http://stackoverflow.com/questions/35963244/how-to-get-device-email-address-in-delphi-10], Thanks again – ColdZer0 Mar 26 '16 at 13:11