Einzelnen Beitrag anzeigen

Benutzerbild von jaenicke
jaenicke

Registriert seit: 10. Jun 2003
Ort: Berlin
9.345 Beiträge
 
Delphi 11 Alexandria
 
#21

AW: Einen REST-Server mit Delphi/CPP Builder erstellen?

  Alt 7. Mai 2015, 20:14
So, hier kommt nun endlich das Beispiel.

Kernstück ist das hier:
Delphi-Quellcode:
var
  VclApplication: TApplication;
  ServiceApplication: TServiceApplication;
begin
  if WebRequestHandler <> nil then
    WebRequestHandler.WebModuleClass := TLogServerDataModule;
  if FindCmdLineSwitch('config') then // normal application with config dialog only
  begin
    VclApplication := Vcl.Forms.Application;
    VclApplication.Initialize;
    VclApplication.MainFormOnTaskbar := True;
    VclApplication.CreateForm(TfrmLogServerConfigDlg, frmLogServerConfigDlg);
    VclApplication.Run;
  end
  else if not AnsiSameText(GetParentProcessName, 'services.exe') and not FindCmdLineSwitch('install')
     and not FindCmdLineSwitch('uninstall') then // normal application
  begin
    VclApplication := Vcl.Forms.Application;
    VclApplication.Initialize;
    VclApplication.MainFormOnTaskbar := True;
    VclApplication.CreateForm(TfrmLogServerTestMain, frmLogServerTestMain);
    VclApplication.CreateForm(TLogServerDataModule, LogServerDataModule);
    LogServerDataModule.RunningAsService := False;
    VclApplication.Run;
  end
  else // service
  begin
    ServiceApplication := Vcl.SvcMgr.Application;
    if not ServiceApplication.DelayInitialize or ServiceApplication.Installing then
      ServiceApplication.Initialize;
    ServiceApplication.CreateForm(TDemoServer, DemoServer);
    ServiceApplication.CreateForm(TLogServerDataModule, LogServerDataModule);
    LogServerDataModule.RunningAsService := True;
    ServiceApplication.Run;
  end;
Sprich der Trick an der Sache ist, dass ich nachschaue, ob der Dienstmanager mein Programm gestartet hat oder der Dienst gerade installiert oder deinstalliert werden soll. Zusätzlich habe ich als Demo mal noch einen Konfigurationsswitch eingebaut.
Sebastian Jänicke
Alle eigenen Projekte sind eingestellt, ebenso meine Homepage, Downloadlinks usw. im Forum bleiben aktiv!

Geändert von Daniel ( 3. Dez 2015 um 13:51 Uhr) Grund: Anhang auf Wunsch des Autors entfernt, korrigierte Fassung s.u.
  Mit Zitat antworten Zitat