unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DateUtils, StdCtrls, ExtCtrls;
type
TForm1 =
class(TForm)
Edit_STunden: TEdit;
Edit_Minuten: TEdit;
Edit_Sekunden: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Label_CountDown: TLabel;
Timer: TTimer;
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure TimerTimer(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
DateTimeEnd : TDateTime;
procedure UpdateCountDown;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var DateTimeNow : TDateTime;
begin
// Aktueller Zeitstempel
DateTimeNow := now;
{ Zu aktuellem Zeitstempel Stunden, Minuten und Sekunden
dazuzählen um Zeitstempel des Countdownendes zu ermitteln }
DateTimeEnd := inchour(DateTimeNow, strtoint(edit_stunden.Text));
DateTimeEnd := incminute(DateTimeEnd, strtoint(edit_minuten.Text));
DateTimeEnd := incsecond(DateTimeEnd, strtoint(edit_sekunden.Text));
{ Timer starten... }
Timer.Enabled := True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Label_Countdown.Caption := '
Inaktiv';
Timer.Enabled := False;
end;
procedure TForm1.TimerTimer(Sender: TObject);
begin
// Falls aktueller Zeitstempel >= Ende dann Timer beenden
if now >= DateTimeEnd
then Begin;
{ hier können dann Aktionen ausgeführt werden... }
timer.Enabled := False;
Showmessage('
Countdown beendet!');
end Else
{ Countdown aktualisieren }
UpdateCountDown
end;
procedure Tform1.UpdateCountDown;
var h, m, s : integer;
hs, ms, ss :
String;
DateTimeTemp : TDateTime;
begin
{ Aktueller Zeitstempel }
DateTimeTemp := Now;
{ Zeitspanne ausrechnen }
{ Stunden }
h := HoursBetween(DateTimeTemp, DateTimeEnd);
hs := InttoStr(h);
if Length(hs) = 1
then hs := '
0' + hs;
DateTimeTemp := IncHour(DateTimeTemp, h);
{ Minuten }
m := MinutesBetween(DateTimeTemp, DateTimeEnd);
ms := InttoStr(m);
if Length(ms) = 1
then ms := '
0' + ms;
DateTimeTemp := IncMinute(DateTimeTemp, m);
{ Sekunden }
s := SecondsBetween(DateTimeTemp, DateTimeEnd);
ss := InttoStr(s);
if Length(ss) = 1
then ss := '
0' + ss;
{ Label ausgeben }
LabeL_CountDown.Caption := Format('
%s:%s:%s', [hs, ms, ss]);
end;
end.