Ver Mensaje Individual
  #19  
Antiguo 15-01-2011
Philip_ Philip_ is offline
No confirmado
 
Registrado: abr 2010
Posts: 8
Reputación: 0
Philip_ Va por buen camino
Mira este ejemplo explica algo

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)
dwTiempoword;
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.
Responder Con Cita