unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TFPrincipal = class(TForm)
EContador: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
Tcontador= class(TThread)
dwTiempo
word;
iSegundos:integer;
Etiqueta:Tlabel;
constructor Create; reintroduce ; overload ;
procedure execute; override;
procedure ActualizarPantalla;
end;
var
FPrincipal: TFPrincipal;
Contador:Tcontador;
implementation
{$R *.dfm}
{ Tcontador }
procedure Tcontador.ActualizarPantalla;
begin
Etiqueta.Caption:=IntToStr(iSegundos);
end;
constructor Tcontador.Create;
begin
inherited Create(True);//lamamos al constructor padre (TThread)
dwTiempo:=GetTickCount;
iSegundos:=0;
end;
procedure Tcontador.execute;
begin
inherited;
//CONTAMOS HASTA 10SEGUNDOS
while iSegundos<10 do
//¿an pasado 1000 milisegundos?
if GetTickCount - dwTiempo>1000 then
begin
//incrementamos el contador de segundos y actualizamos la etiqueta
Inc(iSegundos);
Synchronize(ActualizarPantalla);
//Etiqueta.Caption:=IntToStr(iSegundos);
dwTiempo:=GetTickCount;
end;
end;
procedure TFPrincipal.FormCreate(Sender: TObject);
begin
Contador:=Tcontador.Create(True);
Contador.Etiqueta:=EContador;
Contador.FreeOnTerminate :=True;
Contador.Resume;
end;
end.