Ver Mensaje Individual
  #2  
Antiguo 14-12-2007
Avatar de ixMike
ixMike ixMike is offline
Miembro
 
Registrado: feb 2004
Posts: 1.151
Reputación: 24
ixMike Va por buen camino
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 !!!
end;

end.

Saludos

Última edición por ixMike fecha: 16-12-2007 a las 01:02:52.
Responder Con Cita