Lo que tienes que hacer es crear la unidad del hilo (por una cuestion de proligidad, je) y luego incluirla en el uses de la unidad en la cual usaras ese hilo.
Aca te dejo una unidad que yo uso para hacer descargas desde la web para que veas un ejemplo.
Código Delphi
[-]
unit ThDescarga;
interface
uses
Classes, IdHTTP, Messages, sysutils, IdComponent, shellApi;
type
TDescarga = class(TThread)
procedure SetParam(_WebFile, _Destino: String); Procedure UpdateProg;
private
protected
procedure Execute; override;
public
Progreso: integer;
WebFile: String;
Destino: String
end;
implementation
uses Prin, dialogs, FuncionesVarias;
Procedure TDescarga.UpdateProg;
begin
end;
procedure TDescarga.SetParam(_WebFile, _Destino: String);begin
WebFile:= _WebFile;
Destino:= _Destino;
end;
procedure TDescarga.Execute;
var ArchDestino: TFileStream;
BorrarArch: Boolean;
i: integer;
s, Pass: String;
const a=33;
begin
FreeOnTerminate:=True;
if pos('/PROGRAM/', Principal._Dst)>0 then
begin
Delete(Principal._Dst, 1, 9);
Principal._Dst:= PChar(ExtractFilePath(ParamStr(0)))+Principal._Dst;
end;
if (Principal.Descargando)and((Not FileExists(Principal._Dst))or
(lowercase(ExtractFileExt(Principal._Dst))='.up')) then
begin
if Not DirectoryExists(Principal._Dst) then
ForceDirectories(ExtractFilePath(Principal._Dst));
ArchDestino:=TFileStream.Create(Principal._Dst, fmCreate);
try
BorrarArch:= False;
try
Principal.IdHTTP.Get(Principal._WF, ArchDestino);
except
BorrarArch:= True;
end;
finally
if ArchDestino.Size <> Principal.FTotalBytes then
BorrarArch:= True;
ArchDestino.free;
Principal.Descargando:= False;
Principal.ProgresoDescarga.Visible:= False;
if BorrarArch then
DeleteFile(Principal._Dst)
else
begin
if lowercase(ExtractFileExt(Principal._Dst))='.up' then
begin
Principal.ListaDescarga.Lines.Clear;
Principal.ListaDescarga.Lines.LoadFromFile(Principal._Dst);
Pass:= '#File,Get'+Chr(a+100);
for i:= 0 to Principal.ListaDescarga.Lines.Count - 1 do
begin
s:= Principal.ListaDescarga.Lines[i];
Principal.ListaDescarga.Lines[i]:= DesCifrar(S, Pass);
if Pass='#File,Get'+Chr(a+100) then
Pass:= '#File,Dest'+Chr(a+100)
else Pass:='#File,Get'+Chr(a+100);
end;
DeleteFile(Principal._Dst);
Principal.IdHTTPWorkEnd(Self, wmRead);
end
else if lowercase(ExtractFileExt(Principal._Dst))='.exe' then
begin
try
if (lowercase(ExtractFileName(Principal._Dst))<>'update.exe')then
ShellExecute(0, '', PChar(Principal._Dst), PChar('/'+PChar(ParamStr(0))), '', 0);
except
Principal.Log('Error al Ejecutar: '+Principal._Dst);
end;
end;
end;
end;
end
else
Principal.Descargando:= False;
Principal.ProgresoDescarga.Visible:= False;
end;
end.