alpires
asked on
delphi and TService
Hi Experts
I'm trying to create a service in delphi, but is not working. I am using delphi 7 and windows xp professional.
What's wrong with this code
Alexandre
I'm trying to create a service in delphi, but is not working. I am using delphi 7 and windows xp professional.
What's wrong with this code
Alexandre
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
ExtCtrls;
type
TService1 = class(TService)
Timer1: TTimer;
procedure ServiceExecute(Sender: TService);
procedure Timer1Timer(Sender: TObject);
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;
procedure TService1.ServiceExecute(Sender: TService);
begin
Timer1.Enabled := True;
while not Terminated do
ServiceThread.ProcessRequests(True);
Timer1.Enabled := False;
end;
procedure TService1.Timer1Timer(Sender: TObject);
const
FileName = 'c:\logdate.txt';
var
F: TextFile;
begin
AssignFile(f,FileName);
if FileExists(FileName) then Append(f)
else
Rewrite(f);
writeln(f,DateTimeToStr(Now));
ShowMessage(DateTimeToStr(Now));
CloseFile(f);
end;
end.
ASKER
Yes I'm doing this, but still not working
ASKER
Well, Now I made these changes and worked:
procedure TService1.ServiceExecute(S ender: TService);
begin
Timer1.Enabled := True;
while not self.Terminated do
self.ServiceThread.Process Requests(t rue);
Timer1.Enabled := False;
end;
But now i have some questions:
1- How star the service by another delphi
procedure TService1.ServiceExecute(S
begin
Timer1.Enabled := True;
while not self.Terminated do
self.ServiceThread.Process
Timer1.Enabled := False;
end;
But now i have some questions:
1- How star the service by another delphi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
to start it from the Delphi Ide :
Add "/Install" to the Parameters Edit in Menu Run / Parameters / Tab Local
And hit Run (F9)
Add "/Install" to the Parameters Edit in Menu Run / Parameters / Tab Local
And hit Run (F9)
you need to run it from the cmd prompt
service.exe /install