How to detect if running as an application or service

Hello,

I like the ability to specify whether my server will run as a desktop application or windows service. When running as a desktop app, I use the mainform to display a log of application events in a TMemo component.

However, when I run the server as a windows service, the events need to be logged in the event viewer. How do I determine the current run mode to do something like this:

if <<running_as_service>> then
Write(EVENTLOG_INFORMATION_TYPE, 2, ‘error connecting to the DB…’)
else
ServerForm.memo1.text := ‘error connecting to the DB…’

TIA

Actually figured I can check if ROService is Nil to determine if i’m running a service app…

you can use Combo Standalone Server template.

for File Broadcast sample, FileBroadcastServer.dpr was generated as

  if ROStartService('FileBroadcast', 'FileBroadcast') then begin
    ROService.CreateForm(TFileBroadcastServerDataForm, FileBroadcastServerDataForm);
    ROService.Run;
    Exit;
  end;

  Application.Initialize;
  Application.Title := 'File Broadcast Server';
  Application.CreateForm(TFileBroadcastServerDataForm, FileBroadcastServerDataForm);
  Application.CreateForm(TFileBroadcastServerMainForm, FileBroadcastServerMainForm);
  Application.Run;