membuat timer dengan delpi
membuat timer dengan delpi:
tool yang digunakan adalah:
1. Timer1
2. Button1
3. Button2
4. Button3
5. Edit1
untuk edit 1 text nya dikosongkan
untuk programnya sebagai berikut:
unit countdowntimer;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Timer1: TTimer;
Panel1: TPanel;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
waktusisa : Integer;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
var jam, menit, detik : Word;
begin
dec(waktusisa);
jam:= waktusisa div 3600;
menit:= waktusisa div 60;
detik:= waktusisa - (jam * 3600) - (menit * 60);
Panel1.Caption:=FormatDateTime('hh:mm:ss',EncodeTime(jam,menit,detik,0));
if (waktusisa = 0) then
begin
Timer1.Enabled := False;
end
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
waktusisa:= StrToInt(Edit1.Text);
Timer1.Enabled := True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled := False;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
end.
Comments