Timer
Quero determinar um tempo de 30 segundos para que o usuario digite a senha no formulário, caso isso não aconteça a aplicação deverá ser encerrada.
Consegui colocando um TTimer com a propriedade
Interval = 30000
e no evento
OnTimer = ShowMessage(´Tempo esgotado´);
Passados o 30 segundo beleza ele mosta a menssagem, mas quero apresentar num LABEL o tempo restante e caso passe os 30 segundos ele encerre a aplicação.
Como faço?
Consegui colocando um TTimer com a propriedade
Interval = 30000
e no evento
OnTimer = ShowMessage(´Tempo esgotado´);
Passados o 30 segundo beleza ele mosta a menssagem, mas quero apresentar num LABEL o tempo restante e caso passe os 30 segundos ele encerre a aplicação.
Como faço?
Wgm8
Curtidas 0
Respostas
Jowjow
28/04/2004
(* Declare em Var(no início do Form, acima de implementation a variavel TempoTotal *)
var
TempoTotal: Integer = 0;
...
procedure TForm1.TimerTimer(Sender: TObject);
begin
TempoTotal := TempoTotal + 1;
Label1.Caption := IntToStr(TempoTotal);
if TempoTotal = 30 then
begin
Timer.Enabled := False;
ShowMessage(´O tempo esgotou. O Sistema será encerrado´);
Close;
end;
end;
var
TempoTotal: Integer = 0;
...
procedure TForm1.TimerTimer(Sender: TObject);
begin
TempoTotal := TempoTotal + 1;
Label1.Caption := IntToStr(TempoTotal);
if TempoTotal = 30 then
begin
Timer.Enabled := False;
ShowMessage(´O tempo esgotou. O Sistema será encerrado´);
Close;
end;
end;
GOSTEI 0
Jowjow
28/04/2004
Disculpa, esqueci...
as propriedades devem estar assim:
Enable = True
Interval = 1000
(*
O q ele faz é executar o evento OnTimer no intervalo de tempo definido em Interval, neste caso a cada segundo. Ok?
*)
as propriedades devem estar assim:
Enable = True
Interval = 1000
(*
O q ele faz é executar o evento OnTimer no intervalo de tempo definido em Interval, neste caso a cada segundo. Ok?
*)
GOSTEI 0
Wgm8
28/04/2004
procedure TFormSenha.Timer1Timer(Sender: TObject);
var
Cont,i : integer;
begin
cont:=0;
for i := 1 to 30 do
begin
Cont := Cont + 1;
TempoLA.Caption := IntToStr totime(cont);
end;
if Cont = 30 then
begin
Timer1.Enabled := False;
ShowMessage(´O tempo esgotou. O Sistema será encerrado´);
end;
end;
var
Cont,i : integer;
begin
cont:=0;
for i := 1 to 30 do
begin
Cont := Cont + 1;
TempoLA.Caption := IntToStr totime(cont);
end;
if Cont = 30 then
begin
Timer1.Enabled := False;
ShowMessage(´O tempo esgotou. O Sistema será encerrado´);
end;
end;
GOSTEI 0
Jowjow
28/04/2004
(*
Coloque um label e um Timer no form e faça o teste com uma nova applicação e depois adapte ao seu programa
*)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Label1: TLabel;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
TempoTotal: Integer = 0;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
TempoTotal := TempoTotal + 1;
Label1.Caption := IntToStr(TempoTotal);
if TempoTotal = 60 then
begin
Timer1.Enabled := False;
ShowMessage(´O tempo esgotou. O Sistema será encerrado´);
Close;
end;
end;
end.
Coloque um label e um Timer no form e faça o teste com uma nova applicação e depois adapte ao seu programa
*)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Label1: TLabel;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
TempoTotal: Integer = 0;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
TempoTotal := TempoTotal + 1;
Label1.Caption := IntToStr(TempoTotal);
if TempoTotal = 60 then
begin
Timer1.Enabled := False;
ShowMessage(´O tempo esgotou. O Sistema será encerrado´);
Close;
end;
end;
end.
GOSTEI 0