时间计数器


{ 1 h=1*60 m=1*60*60 s=1*60*60*1000 hs=3600000hs}
function StartCount():string;
{$j+}
const
      h:Integer=0;
      m:Integer=0;
      s:integer=0;
{$j-}
begin
  inc(s);
  if s>=60 then
  begin
    Inc(m);
    s:=0;
  end;
  if m>=60 then
  begin
    Inc(h);
    m:=0;
  end;
  Result:=Format('%.2d:%.2d:%.2d',[h,m,s]);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
label1.Caption:= StartCount();
end;
 
///倒计时
 
function dec1():string;
{$j+}
const i:Integer=60*5;
{$j-}
begin
   Dec(i);
   Result:=Format('剩余时间:%d',[i]);
end;

procedure TForm1.Timer1Timer(Sender: TObject);{$j+}
begin
     label1.Caption:=dec1;
end;


var
  h1: Integer = 0;
  m1: Integer = 0;
  s1: Integer = 0;

procedure TForm2.Timer1Timer(Sender: TObject);
begin
  if (h1 <= 0) and (m1 <= 0) and (s1 <= 0) then
    exit;

  Dec(s1);
  if s1 <= 0 then
  begin
    if (m1 > 0) or (h1 > 0) then
    begin
      Dec(m1);
      s1 := 60;
    end;
  end;
  if m1 < 0 then
  begin
    if h1 > 0 then
    begin
      Dec(h1);
      m1 := 60;
    end;
  end;

  Label1.Caption := Format('%.2d:%.2d:%.2d', [h1, m1, s1]);
end;




posted @ 2014-07-29 16:47  XE2011  阅读(182)  评论(0编辑  收藏  举报