Ver Mensaje Individual
  #2  
Antiguo 29-04-2005
Avatar de hermes_32
hermes_32 hermes_32 is offline
Miembro
 
Registrado: jul 2003
Posts: 94
Reputación: 21
hermes_32 Va por buen camino
Para que tu aplicacion sea un servicio inicia un nuevo proyecto asi:

File -> New -> Other -> Service Application

Este será el aspecto:

Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;

type
  TService1 = class(TService)
  private
    { Private declarations }
  public
    function GetServiceController: TServiceController; override;
    { Public declarations }
  end;

var
  Service1: TService1;

implementation

{$R *.DFM}

procedure ServiceController(CtrlCode: DWord); stdcall;
begin
  Service1.Controller(CtrlCode);
end;

function TService1.GetServiceController: TServiceController;
begin
  Result := ServiceController;
end;

end.

Ahora tienes que implementar tú los métodos:

Código Delphi [-]
    procedure ServiceStart(Sender: TService; var Started: Boolean);
    procedure ServiceStop(Sender: TService; var Stopped: Boolean);

Me imagino que querrás que realice cada cierto tiempo una acción. Pues no puedes poner un Timer así por las buenas. Debes crearlo:

Código Delphi [-]
  .
  .
  .
    private
      { Private declarations }
      Timer: TTimer; 
  .
  .
  .

Y al comenzar el servicio:

Código Delphi [-]
    procedure ServiceStart(Sender: TService; var Started: Boolean);
    begin
      Timer:=TTimer.Create(nil);
      Timer.Interval := Intervalo;
      Timer.OnTimer:=TimerOnTimer; //aquí la acción 
    end;

Y al terminar el servicio:

Código Delphi [-]
    procedure ServiceStop(Sender: TService; var Stopped: Boolean);
    begin
     Timer.Free;
     Timer:=nil;      
    end;

Bueno esto es mas o menos el trabajo. Espero que te ayude.
Responder Con Cita