Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Algo falta para activar el timer. (https://www.clubdelphi.com/foros/showthread.php?t=24305)

Antuan 16-08-2005 08:40:51

Algo falta para activar el timer.
 
Ya sabeis que soy novato y no se pero algo me falta para activar en timer en el label1 sin tener que poner el componente timer graficamente en el form1.
este es el Codigo:
Código Delphi [-]
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;
type
  TForm1 = class(TForm)
    Label1: TLabel;
    procedure Timer1Timer(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    Timer1: TTimer;
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  Contador: Integer;
implementation
{$R *.dfm}
function GetCounter(Second: Integer): string;
var
  Minute, NewSecond, Hour: Currency;
begin
  Hour       := Int(Second / 3600);
  Minute     := Int((Second - (Hour * 3600)) / 60);
  NewSecond  := Second - int(Hour * 3600 + Minute * 60);
  GetCounter := CurrToStr(Hour) + ':' + CurrToStr(Minute) + ':' + CurrToStr(NewSecond);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Timer1 := TTimer.Create(Form1);
with Timer1 do
begin
  Enabled := True;
  Interval := 1000;
  Name := 'Timer1';
  Tag := 0;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  label1.Caption := GetCounter(GetTickCount div 1000 - Contador div 1000);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Contador := GetTickCount;
end;
end.
Y no se que me falta, para que me funcione.
Gracias

German 16-08-2005 09:37:43

Código Delphi [-]
with Timer1 do
begin
  Interval := 1000;
  onTimer := Timer1Timer;
  Enabled := True;
end;

Salu2

Antuan 16-08-2005 11:36:01

Ahora otra cosita si puede ser
 
Tengo el reloj funcionando y cualdo alcanza un tiempo presento un mensaje.
Como vuelvo a ponerlo a '0'
Código Delphi [-]
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  label1.Caption := GetCounter(GetTickCount div 1000 - Contador div 1000);
  Tiempo := GetCounter(GetTickCount div 1000 - Contador div 1000);
  If Tiempo = '0:0:30' then
  ShowMessage( 'Esto es una prueba')
end;
Muchas gracias por vuestras respuestas

jmariano 16-08-2005 14:56:52

Saludos!

Podrías volver a igualar la variable "Contador" al valor de la función "GetTickCount" (como haces en el evento "OnCreate" del formulario) en la misma sentencia "If" (donde muestras el mensaje) para así volver a contar la diferencia de tiempo transcurrido.

Código Delphi [-]
procedure TForm1.Timer1Timer(Sender: TObject);
begin 
  label1.Caption := GetCounter(GetTickCount div 1000 - Contador div 1000); 
  Tiempo := GetCounter(GetTickCount div 1000 - Contador div 1000); 
  
  If Tiempo = '0:0:30' then 
  begin 
    ShowMessage( 'Esto es una prueba'); 
    Contador := GetTickCount; 
  end;
end;

Chao!


La franja horaria es GMT +2. Ahora son las 14:22:45.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi