Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Consulta Sobre Timer (https://www.clubdelphi.com/foros/showthread.php?t=51409)

BetoAlonso 14-12-2007 14:55:35

Consulta Sobre Timer
 
Saludos

alguien sabe como crear un timer en tiempo de ejecución.

gracias

ixMike 14-12-2007 15:09:20

Hola.

Pues declaras una variable tipo TTimer, lo creas cuando lo necesites con el método Create, le asignas un procedure al evento OnTimer, y cuando ya no lo necesites, pues lo liberas de la memoria mediante Destroy.

Un ejemplo:

Código Delphi [-]
unit Unit1;

interface

uses
  Windows, SysUtils, Forms, ExtCtrls;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
    Procedure ProcTimer(Sender: TObject);
  end;

var
  Form1: TForm1;
  Reloj: TTimer;
  Contador: Integer;

implementation

{$R *.DFM}

procedure TForm1.ProcTimer(Sender: TObject);
begin
Inc(Contador);
Caption:=IntToStr(Contador);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Contador:=0;
Reloj:=TTimer.Create(Self); //Creamos el TTimer
Reloj.OnTimer:=ProcTimer;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Reloj.Destroy;  //Quitamos el TTimer de memoria... ¡¡¡que Windows ya chupa mucha :D:D!!!
end;

end.

Saludos ;)


La franja horaria es GMT +2. Ahora son las 23:04:51.

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