Fórum Cronometro usando Ttimer. #617974
26/04/2022
0
Paulo Oliveira
Curtir tópico
+ 0Post mais votado
27/04/2022
Declare a variavel global maxtime:
var maxtime: real;
No onshow do form desative o Timer:
Timer1.Enabled := False;
No OnClick do button acione o cronometro:
maxtime := strtotime('00:00:00');
Timer1.Enabled := True;No Ontimer do Timer o procedimento para correr o tempo:
maxtime := maxtime + strtotime('00:00:01');
Label1.Caption := timetostr(maxtime);
Application.ProcessMessages;
if timetostr(maxtime) = Edit1.Text then
begin
Timer1.Enabled := False;
ShowMessage('Tempo finalizado!');
end;Código completo:
unit Unit13;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
type
TForm13 = class(TForm)
Timer1: TTimer;
Edit1: TEdit;
Label1: TLabel;
Button1: TButton;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form13: TForm13;
maxtime: real;
implementation
{$R *.dfm}
procedure TForm13.Button1Click(Sender: TObject);
begin
maxtime := strtotime('00:00:00');
Timer1.Enabled := True;
end;
procedure TForm13.FormShow(Sender: TObject);
begin
Timer1.Enabled := False;
end;
procedure TForm13.Timer1Timer(Sender: TObject);
begin
maxtime := maxtime + strtotime('00:00:01');
Label1.Caption := timetostr(maxtime);
Application.ProcessMessages;
if timetostr(maxtime) = Edit1.Text then
begin
Timer1.Enabled := False;
ShowMessage('Tempo finalizado!');
end;
end;
end.Natanael Ferreira
Gostei + 1
Mais Posts
28/04/2022
Paulo Oliveira
Gostei + 0
28/04/2022
Paulo Oliveira
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)