Cara membuat Stopwatch di Dhelpi

Cara membuat Stopwatch di Dhelpi ( Embarcadero radstudio 2010 )

 

1. buka program delphinya( pastikan kamu sudah menginstal aplikasi dhelpinya)
2. buat form yang isi nya ada 2 Button, 2 label, 1 timer dengan desain seperti ini gan..

 
3. trus tinggal ikuti perintah-perintah ini, masukan script di bawah ini ya !
   pastikan kamu tidak salah atau kurang script ini sedikitpun, bisa jadi nanti kamu gagal



unit Unit1;

interface

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

type
TForm1 = class(TForm)
Label1: TLabel;
Timer1: TTimer;
Button2: TButton;
Button3: TButton;
Label2: TLabel;
suiURLLabel1: TsuiURLLabel;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
StartTime,StopTime: TDateTime;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
// perintah untuk formnya(caranya doble klik formnya)
Timer1.enabled := false;
end;

function waktunya(wkt: double): string;
var
VTime: double;
Hari,Jam,Menit: integer;
detik: double;
begin
If int(wkt) > 0 then
Hari := 0 else Hari := Trunc(wkt);

wkt := Frac(wkt) * 24; // untuk jam
Jam := Trunc(wkt);

wkt := frac(wkt) * 60; // untuk Menit
Menit := Trunc(wkt);

detik := frac(wkt) * 60; // untuk detik

Result := IntToStr(Hari) + ' Hari, ' +
IntToStr(Jam) + ' Jam, '+
IntToStr(Menit) + ' menit, ' +
FloatToStrF(detik, ffFixed,15,2) + ' detik';
end;

procedure TForm1.FormShow(Sender: TObject);
begin
// perintah untuk form shownya(caranya pilih formnya lalu klik event OnShow)
Button3.Caption := '&Start';
Label1.Caption := waktunya(0.0);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
CTime: TDateTime;
ETime: double;
begin
// perintah untuk Timernya)
CTime := now;
ETime := CTime - StartTime;
Label1.caption := waktunya(ETime);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
// perintah untuk Tombol 2 (RESET)
If Timer1.Enabled=True Then
showmessage('Tekan Stop terlebih dahulu baru reset....!!')
else
Label1.caption := waktunya(0.0);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
// perintah untuk Tombol 2 (STAR)
if Button3.Caption = '&Start' then
begin
StartTime := now;
Label1.caption := waktunya(0.0);
Timer1.enabled := true;
Button3.Caption := '&Stop';
end else
begin
Timer1.enabled := false;
StopTime := now;
Button3.Caption := '&Start';
end;
end;

end.


Selamat mencoba !!
Good Luck :D

-INDAHNYA BERBAGI -

 

Share this

Related Posts

Previous
Next Post »