Dunia Baruku Photography

Dibawah Ini Hasil Penggabungan dan Otak-atik yang semalam aku kerjakan hanya karena penasaran dan ingin tau seperti apa hasilnya. Lihat Hasilnya disini–> Stapwacth yang udah aku coba, sederhana tapi asyik buat menambah wawasan. Ada beberapa yang modifikasi juga. Jika teman-teman ingin mencoba silahkan saja tinggal pakai source codenya. Tinggal Pengaturan Intervalnya saja. Jangan dianggap saya sombong dengan hasil karya saya ini, saya juga baru belajar. karena saya ingin mengikat ilmu saya dengan menuliskannya diblog ini. siapa tau ada yang membutuhkannya untuk dasar pembelajaran delphi. Bahkan saya sangat berharap akan ada yang saling memberikan ilmu.  Harapan saya  tulisan saya ini bermanfaat buat saya dan teman-teman semua.. Ok Thanks.. Dibawah ini Sourcecodenya.

unit UStopwatch;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
LblTime: TLabel;
butss: TButton;
Timer1: TTimer;
Button1: TButton;
Panel1: TPanel;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure butssClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
var
StartTime,
StopTime: TDateTime;

procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.enabled := false;
end;

function ElapsedTimeStr(ETime: double): string;
var
RTime: double;
Days, Hrs, Mins: integer;
Secs: double;
begin
if int(ETime) > 0 then Days := 0 // Pengitungan Hari
else Days := Trunc(ETime);

RTime := frac(ETime) * 24; // Konversi Untuk jam disini
Hrs := Trunc(RTime);

RTime := frac(RTime) * 60; // Konversi Untuk Menit
Mins := Trunc(RTime);

Secs := frac(RTime) * 60; // Konbersi Untuk MiliDetik

Result := IntToStr(Days) + ‘ days, ‘ +
IntToStr(Hrs) + ‘ hrs, ‘ +
IntToStr(Mins) + ‘ mins, ‘ +
FloatToStrF(Secs, ffFixed,15,2) + ‘ secs’;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
butSS.Caption := ‘&Start’;
lblTime.Caption := ElapsedTimeStr(0.0);
end;

procedure TForm1.butssClick(Sender: TObject);
begin
if butSS.Caption = ‘&Start’ then begin
StartTime := now;
lblTime.caption := ElapsedTimeStr(0.0);
Timer1.enabled := true;
butSS.Caption := ‘&Stop’;
// showmessage(‘Sedang Menghitung ‘);
end
else begin //butSS.Caption := ‘&Stop’
Timer1.enabled := false;
//lblTime.caption := ElapsedTimeStr(0.0); Jika diapakai Akan Mereset jadi Nol lagi
StopTime := now;
butSS.Caption := ‘&Start’;
showmessage(‘Yes, You Can Reset Now!!’);
end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
CTime: TDateTime;
ETime: double; // the elapsed time in decimal days
begin
CTime := now;
ETime := CTime – StartTime;
lblTime.caption := ElapsedTimeStr(ETime);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
lblTime.caption := ElapsedTimeStr(0.0);
showmessage(‘You Must Stop before Reset !!’);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
showmessage(‘Are You Sure to Close ?’);
close;
end;

end.

Untuk dfm-nya dibawah ini : // Silahkan Anda ganti sesuai selera anda..

object Form1: TForm1
Left = 453
Top = 299
Width = 281
Height = 195
Caption = ‘Stopwatch’
Color = clSkyBlue
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = ‘MS Sans Serif’
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object LblTime: TLabel
Left = 16
Top = 40
Width = 209
Height = 15
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = ‘200proofmoonshine’
Font.Style = []
ParentFont = False
end
object butss: TButton
Left = 24
Top = 112
Width = 75
Height = 25
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = ‘200proofmoonshine’
Font.Style = []
ParentFont = False
TabOrder = 0
OnClick = butssClick
end
object Button1: TButton
Left = 104
Top = 112
Width = 75
Height = 25
Caption = ‘Reset’
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = ‘200proofmoonshine’
Font.Style = []
ParentFont = False
TabOrder = 1
OnClick = Button1Click
end
object Panel1: TPanel
Left = 0
Top = 0
Width = 273
Height = 25
Align = alTop
Caption = ‘Aplikasi Stopwatch’
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = ‘200proofmoonshine’
Font.Style = []
ParentFont = False
TabOrder = 2
end
object Button2: TButton
Left = 184
Top = 112
Width = 75
Height = 25
Caption = ‘Close’
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = ‘200proofmoonshine’
Font.Style = []
ParentFont = False
TabOrder = 3
OnClick = Button2Click
end
object Timer1: TTimer
Enabled = False
Interval = 10
OnTimer = Timer1Timer
Left = 24
Top = 72
end
end

Untuk teman-teman semua selamat mencoba. Tidak ada yang sulit jika kita mau mencoba. Dan kegagalan juga bukan menjadi halangan untuk berhenti. Jika ada saran atau commentar silahkan anda tuliskan comment. Saran dan kritik anda sangat berarti baru saja. terimakasih

www.maspiping.com

Comments on: "Aplikasi Sederhana Stopwatch dengan Delphi" (4)

  1. yos sitompul said:

    Hohoho trimakasih atas codenya! Button1Click blum cover yang uda distop tu. Thx.

  2. Terimakasih mas Yos Sitompul atas komentarnya, Senang bisa bertukar ilmu, jika ada saran lagi atau trik2 lain sharing yah..!! Salam kenal dari maspiping.

  3. rosy kartika said:

    tapi pas bingungnya saya pada form itu kok gak dijelasin… hehehhe
    maklum masih baru blajar delphi… hiihihih

  4. kartika said:

    bang button butss itu yang seperti apa?

Leave a reply to yos sitompul Cancel reply