Ver Mensaje Individual
  #2  
Antiguo 23-10-2008
Avatar de elcolo83
elcolo83 elcolo83 is offline
Miembro
 
Registrado: feb 2007
Ubicación: Argentina
Posts: 65
Reputación: 18
elcolo83 Va por buen camino
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);//; _ObjProg: TObject);
    Procedure UpdateProg;
  private
    { Private declarations }
  protected
    procedure Execute; override;
  public
    Progreso: integer;
    //ObjProg: TObject;
    WebFile: String;
    Destino: String
  end;

implementation

{ Important: Methods and properties of objects in visual components can only be
  used in a method called using Synchronize, for example,

      Synchronize(UpdateCaption);

  and UpdateCaption could look like,

    procedure Descarga.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }

{ Descarga }
uses Prin, dialogs, FuncionesVarias;

Procedure TDescarga.UpdateProg;
begin
  //Principal.ProgresoDescarga.Position:=
end;

procedure TDescarga.SetParam(_WebFile, _Destino: String);//; _ObjProg: TObject);
begin
  WebFile:= _WebFile;
  Destino:= _Destino;
//  ObjProg:= _ObjProg;
end;


procedure TDescarga.Execute;
var ArchDestino: TFileStream;
    BorrarArch: Boolean;
    i: integer;
    s, Pass: String;
const a=33;
begin
  { Place thread code here }
 { with TidHttp.Create(self)do
    try

    finally
      Free;
    end;}
//OnTerminate:= Principal.SubMenu.OnClick;
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;
              {if (lowercase(ExtractFileName(Principal._Dst))='update.exe')then
                  Principal.AutoClose.Enabled:= True;}
            end;
        end;
    end;
  end
else
  Principal.Descargando:= False;
  Principal.ProgresoDescarga.Visible:= False;
end;
end.
Responder Con Cita