Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit MainFormUnit;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
- StdCtrls, DateUtils;
- type
- { TMainForm }
- TMainForm = class(TForm)
- RestartButton: TButton;
- CountdownLabel: TLabel;
- TimeoutTimer: TTimer;
- procedure FormCreate(Sender: TObject);
- procedure Restart(Sender: TObject);
- procedure UpdateCountdownLabel(Sender: TObject);
- private
- procedure SetTimeoutDate();
- private
- TimeoutDate: TDateTime;
- end;
- const
- COUNTDOWN_SECONDS = 5;
- var
- MainForm: TMainForm;
- implementation
- {$R *.lfm}
- { TMainForm }
- procedure TMainForm.Restart(Sender: TObject);
- begin
- SetTimeoutDate();
- end;
- procedure TMainForm.UpdateCountdownLabel(Sender: TObject);
- begin
- if TimeoutDate >= Now then
- begin
- CountdownLabel.Caption := 'Pozostalo ' + IntToStr(SecondsBetween(TimeoutDate, Now)) + 's';
- end;
- end;
- procedure TMainForm.FormCreate(Sender: TObject);
- begin
- SetTimeoutDate();
- UpdateCountdownLabel(nil);
- end;
- procedure TMainForm.SetTimeoutDate;
- begin
- self.TimeoutDate := IncSecond(Now, COUNTDOWN_SECONDS);
- UpdateCountdownLabel(nil);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement