Advertisement
Guest User

Untitled

a guest
Jun 16th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.19 KB | None | 0 0
  1. unit MainFormUnit;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  9.   StdCtrls, DateUtils;
  10.  
  11. type
  12.  
  13.   { TMainForm }
  14.  
  15.   TMainForm = class(TForm)
  16.     RestartButton: TButton;
  17.     CountdownLabel: TLabel;
  18.     TimeoutTimer: TTimer;
  19.     procedure FormCreate(Sender: TObject);
  20.     procedure Restart(Sender: TObject);
  21.     procedure UpdateCountdownLabel(Sender: TObject);
  22.  
  23.   private
  24.     procedure SetTimeoutDate();
  25.  
  26.   private
  27.     TimeoutDate: TDateTime;
  28.   end;
  29.  
  30.  
  31. const
  32.   COUNTDOWN_SECONDS = 5;
  33.  
  34. var
  35.   MainForm: TMainForm;
  36.  
  37. implementation
  38.  
  39. {$R *.lfm}
  40.  
  41. { TMainForm }
  42.  
  43. procedure TMainForm.Restart(Sender: TObject);
  44. begin
  45.   SetTimeoutDate();
  46. end;
  47.  
  48. procedure TMainForm.UpdateCountdownLabel(Sender: TObject);
  49. begin
  50.   if TimeoutDate >= Now then
  51.   begin
  52.     CountdownLabel.Caption := 'Pozostalo ' + IntToStr(SecondsBetween(TimeoutDate, Now)) + 's';
  53.   end;
  54. end;
  55.  
  56. procedure TMainForm.FormCreate(Sender: TObject);
  57. begin
  58.   SetTimeoutDate();
  59.   UpdateCountdownLabel(nil);
  60. end;
  61.  
  62. procedure TMainForm.SetTimeoutDate;
  63. begin
  64.   self.TimeoutDate := IncSecond(Now, COUNTDOWN_SECONDS);
  65.   UpdateCountdownLabel(nil);
  66. end;
  67.  
  68. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement