Tema: Cronometro
Ver Mensaje Individual
  #3  
Antiguo 24-08-2006
[egostar] egostar is offline
Registrado
 
Registrado: feb 2006
Posts: 6.561
Reputación: 25
egostar Va camino a la fama
Post

Hola grone35

Alguna vez tuve la necesidad de hacer un cronometro y te lo dejo aqui por si te sirve o te da una idea de como hacerlo.

Código Delphi [-]
 
var
  Form1: TForm1;
  Present : TDateTime;
  Hour,Min,Sec,MSec: Word;
 
implementation
 
{$R *.DFM}
 
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  inc(MSec);
  If MSec = 100 then begin
     Sec := Sec + 1;
     MSec := 0;
  end;
  If Sec = 60 then begin
     Min := Min + 1;
     Sec := 0;
  end;
  If Min = 60 then begin
     Hour := Hour + 1;
     Min  := 0;
  end;
  Present := EncodeTime(Hour, Min, Sec, MSec);
  Label1.Caption := TimetoStr(Present)+' '+inttostr(MSec);;
end;
 
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  If Timer1.Enabled = False then begin
     Timer1.Enabled := True;
     BitBtn1.Caption := 'Pausa';
  end
  else begin
         Timer1.Enabled := False;
         BitBtn1.Caption := 'Inicia';
       end;
end;
 
procedure TForm1.FormShow(Sender: TObject);
begin
  Present := EncodeTime(0,0,0,0);
  Label1.Caption := '00:00:00 00';
end;

Use un timer con un intervalo de 1 milisegundo, un label y un bitbtn.

Espero que tambien sirva a alguien mas ya que en su momento me dio dolores de cabeza.

Saludos
__________________
"La forma de empezar es dejar de hablar y empezar a hacerlo." - Walt Disney
Responder Con Cita