Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 23-10-2008
pablopessoa pablopessoa is offline
Miembro
 
Registrado: may 2008
Ubicación: Argentina
Posts: 162
Poder: 16
pablopessoa Va por buen camino
como crear hilos de ejecucion en delphi 2007

hola gente, estoy usando Code Gear delphi for win32 y quiero hacer un hilo de ejecucion para un proceso. Busque en internet y encontre esto :

Código Delphi [-]
//Para ello lo que hacemos es crear un hilo de ejecución heredando de la clase TThread del siguiente modo:

THilo = class( TThread )
  Ejecutar: procedure of object;
  procedure Execute; override;
end;

//La definición anterior hay que colocarla dentro del apartado Type de nuestra unidad

pero cuando agrego la unidad me dice que falta el archivo TThread.dcu.

me pongo a mirar las componentes de delphi y hay una que dice Thread Object, pero no se como se usa, alguien me puede ayudar?

muchas gracias!!!

Última edición por dec fecha: 23-10-2008 a las 18:26:37.
Responder Con Cita
  #2  
Antiguo 23-10-2008
Avatar de elcolo83
elcolo83 elcolo83 is offline
Miembro
 
Registrado: feb 2007
Ubicación: Argentina
Posts: 65
Poder: 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
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
como crear dll en tiempo de ejecucion Maycoll Varios 12 10-05-2008 01:57:19
Como crear aplicacion MultiCapa Delphi 2007 elopezf Conexión con bases de datos 0 06-09-2007 23:04:48
con delphi 2007 for php, Crear un nuevo tema? poliburro Debates 13 27-04-2007 20:16:24
Aplicacion con varios Hilos de Ejecución samantha jones Varios 1 02-03-2005 17:27:24
Hilos de ejecucion el toluca Varios 2 29-06-2004 22:59:04


La franja horaria es GMT +2. Ahora son las 21:57:22.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi