叮
叮当猫
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
ExtCtrls;
type
TService1 = class(TService)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServiceStop(Sender: TService; var Stopped: Boolean);
private
{ Private declarations }
public
function GetServiceController: TServiceController; override;
{ Public declarations }
end;
var
Service1: TService1;
i:integer;
StrLstTmp:TstringList;
implementation
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
Service1.Controller(CtrlCode);
end;
function TService1.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TService1.Timer1Timer(Sender: TObject);
begin
//showmessage('haha');
i:=i+1;
Strlsttmp.Add(inttostr(i));
end;
procedure TService1.ServiceStart(Sender: TService; var Started: Boolean);
begin
i:=0;
timer1.Enabled:=true;
StrLstTmp:=TstringList.Create;
end;
procedure TService1.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
//ShowMessage(inttostr(i));
StrLsttmp.SaveToFile('d:/service.txt');
StrLsttmp.Free;
end;
end.
其中TIMER1的时间间隔设置为5000;
请问这样写服务有问题吗?我只是做个测试,这么写,可是竟然不行,服务停止不了?
我设置服务为可以停止和暂停,启动类型为手动,可是怎么会这样呢?
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
ExtCtrls;
type
TService1 = class(TService)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServiceStop(Sender: TService; var Stopped: Boolean);
private
{ Private declarations }
public
function GetServiceController: TServiceController; override;
{ Public declarations }
end;
var
Service1: TService1;
i:integer;
StrLstTmp:TstringList;
implementation
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
Service1.Controller(CtrlCode);
end;
function TService1.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TService1.Timer1Timer(Sender: TObject);
begin
//showmessage('haha');
i:=i+1;
Strlsttmp.Add(inttostr(i));
end;
procedure TService1.ServiceStart(Sender: TService; var Started: Boolean);
begin
i:=0;
timer1.Enabled:=true;
StrLstTmp:=TstringList.Create;
end;
procedure TService1.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
//ShowMessage(inttostr(i));
StrLsttmp.SaveToFile('d:/service.txt');
StrLsttmp.Free;
end;
end.
其中TIMER1的时间间隔设置为5000;
请问这样写服务有问题吗?我只是做个测试,这么写,可是竟然不行,服务停止不了?
我设置服务为可以停止和暂停,启动类型为手动,可是怎么会这样呢?