program DataSnapVCLService;
uses
  Vcl.SvcMgr,
  System.SysUtils,
  CodeSiteLogging,
  ServerMethodsUnit1 in 'ServerMethodsUnit1.pas' {ServerMethods1: TDSServerModule},
  ServerContainerUnit1 in 'ServerContainerUnit1.pas' {ServerContainer1: TService};

{$R *.RES}

{$IFDEF DEBUG}
var
  Destination: TCodeSiteDestination;
{$ENDIF}
begin
  // Windows 2003 Server requires StartServiceCtrlDispatcher to be
  // called before CoRegisterClassObject, which can be called indirectly
  // by Application.Initialize. TServiceApplication.DelayInitialize allows
  // Application.Initialize to be called from TService.Main (after
  // StartServiceCtrlDispatcher has been called).
  //
  // Delayed initialization of the Application object may affect
  // events which then occur prior to initialization, such as
  // TService.OnCreate. It is only recommended if the ServiceApplication
  // registers a class object with OLE and is intended for use with
  // Windows 2003 Server.
  //
  // Application.DelayInitialize := True;
  //
  if not Application.DelayInitialize or Application.Installing then
    Application.Initialize;
  {$IFDEF DEBUG}
  CodeSite.Enabled := True;
  CodeSite.Enabled := CodeSite.Installed;
  if CodeSite.Enabled then
  begin
    CodeSiteManager.ConnectUsingTcp; // for DataSnap services...
    Destination := TCodeSiteDestination.Create(Application);
    Destination.LogFile.Active := True;
    Destination.LogFile.FileName := 'DataSnapServerService.csl'; // hardcoded name
    Destination.LogFile.FilePath := '$(MyDocs)\My CodeSite Files\Logs\';
    Destination.Viewer.Active := True; // also show Live Viewer
    CodeSite.Destination := Destination;
    CodeSite.Clear;
    CodeSite.Send('DataSnap Server Service loaded')
  end;
  {$ELSE}
  CodeSite.Enabled := False;
  {$ENDIF}
  Application.CreateForm(TServerContainer1, ServerContainer1);
  Application.Run;
end.

