delphimvcframework/samples/windowsservice/ServiceU.pas

67 lines
1.3 KiB
ObjectPascal
Raw Normal View History

2019-09-25 14:55:39 +02:00
unit ServiceU;
interface
uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.SvcMgr,
Vcl.Dialogs,
IdHTTPWebBrokerBridge;
type
TArticlesService = class(TService)
procedure ServiceCreate(Sender: TObject);
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServiceStop(Sender: TService; var Stopped: Boolean);
private
fServer: TIdHTTPWebBrokerBridge;
public
function GetServiceController: TServiceController; override;
end;
var
ArticlesService: TArticlesService;
implementation
uses
Web.WebReq,
WebModuleUnit1;
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
ArticlesService.Controller(CtrlCode);
end;
function TArticlesService.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TArticlesService.ServiceCreate(Sender: TObject);
begin
if WebRequestHandler <> nil then
WebRequestHandler.WebModuleClass := WebModuleClass;
end;
procedure TArticlesService.ServiceStart(Sender: TService; var Started: Boolean);
begin
fServer := TIdHTTPWebBrokerBridge.Create(nil);
fServer.DefaultPort := 8080;
fServer.Active := True;
end;
procedure TArticlesService.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
fServer.Free;
end;
end.