Aca te adapte un ejemplo que tenía para que funcione como componente.
Probalo.
Te podes basar en él para el tuyo.
Código Delphi
[-]
unit ProgressThread;
interface
uses
Classes, SysUtils, ComCtrls;
type
TProgressThread = class(TThread)
private
Progreso: Word;
blnStop: Boolean;
procedure UpdateControl;
protected
procedure Execute; override;
public
Progress: TComponent;
procedure Stop;
end;
TProgressAutoInc = class(TProgressBar)
private
FActivo: Boolean;
Thread: TProgressThread;
public
property Activo: boolean read FActivo;
constructor Create(AOwner: TComponent); override;
procedure Play;
procedure Stop;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TProgressAutoInc]);
end;
procedure TProgressThread.Execute;
begin
if (Progress is TProgressBar) then
with Progress as TProgressBar do
Progreso := Position;
blnStop := False;
while ( (not blnStop) and (not Terminated) and (Progreso<=100) ) do
begin
Inc(Progreso);
Synchronize(UpdateControl);
Sleep(50);
if Progreso=100 then Progreso := 0;
end;
end;
procedure TProgressThread.Stop;
begin
blnStop := True;
end;
procedure TProgressThread.UpdateControl;
begin
if (Progress is TProgressBar) then
with Progress as TProgressBar do
Position := Progreso;
end;
procedure TProgressAutoInc.Play;
begin
Thread := TProgressThread.Create(true);
with Thread do
begin
Progress := Self;
FreeOnTerminate := true;
Priority := tpNormal;
end;
Thread.Resume;
FActivo := true;
end;
procedure TProgressAutoInc.Stop;
begin
if FActivo then
Thread.Stop;
FActivo := false;
end;
constructor TProgressAutoInc.Create(AOwner: TComponent);
begin
inherited create(AOwner);
FActivo := false;
end;
end.