Advertisement
kura2yamato

timer jam (delphi 7)

May 15th, 2019
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.35 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, ExtCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Timer1: TTimer;
  12.     lblJam: TLabel;
  13.     btnStart: TButton;
  14.     btnStop: TButton;
  15.     procedure btnStartClick(Sender: TObject);
  16.  
  17.     procedure Timer1Timer(Sender: TObject);
  18.     procedure FormCreate(Sender: TObject);
  19.     procedure btnStopClick(Sender: TObject);
  20.   private
  21.     { Private declarations }
  22.   public
  23.     { Public declarations }
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.   StartTime, StopTime: TDateTime;
  29.  
  30. implementation
  31.  
  32. {$R *.dfm}
  33.  
  34. procedure TForm1.btnStartClick(Sender: TObject);
  35. begin
  36.   timer1.Enabled := true;
  37.   btnStart.Enabled := false;
  38.   btnStart.Font.Color := clGray;//clWindowText
  39.   btnStop.Enabled := true;
  40.   btnStop.Font.Color := clWindowText;
  41.   lblJam.Caption:='Memulai perhitungan';
  42. end;
  43.  
  44. //procedure TForm1.btnStopClick(Sender: TObject);
  45. //begin
  46. //  timer1.Enabled := false;
  47. //  btnStart.Enabled := TRUE;
  48. //  btnStart.Font.Color := clWindowText;//clWindowText
  49. //  btnStop.Enabled := false;
  50. //  btnStop.Font.Color := clGray;
  51. //  StartTime := 0;
  52. //end;
  53.  
  54. function waktu(wkt: double): string;
  55. var
  56.   //dTime: double;
  57.   iHari, iJam, iMenit: integer;
  58.   iDetik: double;
  59.  
  60.   //sResult: Text;
  61. begin
  62.   if int(wkt) > 0 then
  63.     iHari := 0
  64.   else
  65.     iHari := Trunc(wkt);
  66.  
  67.   wkt := Frac(wkt) * 24; // untuk jam
  68.   iJam := Trunc(wkt);
  69.   wkt := frac(wkt) * 60; // untuk Menit
  70.   iMenit := Trunc(wkt);
  71.   iDetik := frac(wkt) * 60; // untuk detik
  72.   result := IntToStr(iHari) + ' Hari, ' + IntToStr(iJam) + ' Jam, ';
  73.   result := result + IntToStr(iMenit) + ' menit, ';
  74.   result := result + FloatToStrF(iDetik, ffFixed, 15, 0) + ' detik';
  75.  
  76.   //return Result;
  77.  
  78. end;
  79.  
  80. procedure TForm1.Timer1Timer(Sender: TObject);
  81. var
  82.   CTime: TDateTime;
  83.   dTime: double;
  84. begin
  85.   if StartTime = 0 then
  86.     StartTime := now;
  87.   CTime := now;
  88.   dTime := CTime - StartTime;
  89.   lblJam.Caption := waktu(dTime);
  90. end;
  91.  
  92. procedure TForm1.FormCreate(Sender: TObject);
  93. begin
  94.   StartTime := 0;
  95.   lblJam.Caption := '';
  96. end;
  97.  
  98. procedure TForm1.btnStopClick(Sender: TObject);
  99. begin
  100.   timer1.Enabled := false;
  101.   btnStart.Enabled := true;
  102.   btnStart.Font.Color := clWindowText;//clWindowText
  103.   btnStop.Enabled := false;
  104.   btnStop.Font.Color := clGray;
  105.   StartTime := 0;
  106. end;
  107.  
  108. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement