<?xml version="1.0" encoding="utf-8"?>
<CrossEngineApp Version="1">
  <Options>object ProjOption: TProjectOptions
  Title = 'dimStatGui'
  AppName = 'dimStatGui'
  Language = 'PASCAL'
  AppIcon.Data = {
[encoded data, 24771 characters]
    0D0A00000000000020200000000000002020
  }
  AppAutor = 'Copyright (c) 2021-2023 Alexey Kuryakin kouriakine@mail.ru'
  MinVMajor = 2
  MinVMinor = 1
  MinVRevision = 2
  ExternalPath = '$DIESELPASCAL_EXTERNAL;$DIESEL_LOCALSET_DIR/external;$DIESEL_EXE_DIR/external;'
  AutoCreateExternal.Strings = (
    'dpAntiZombie'
    'dpGuiResMain'
  )
end
</Options>
  <Metadata>
    <dimStatGui ImageIndex="2">
      <Object ClassName=""/>
      <Code>program dimStatGui;

uses dpCmdArgs,dpSystem,dpSysUtils,dpWindows,dpVbs,dpCrwDaqSys,dpDaqConfig,
     dpGuiResMain,Main;

begin
  InitGuiResMain; // Init GUI Resources - Main
  SetCrwDaqChildTitle('DIM Stat GUI Utility');
  if InstanceRunning(ValidateInstanceName(GetCrwDaqChildTitle),true) then begin
   AppActivateByClassTitle('Window',GetCrwDaqChildTitle);
   Application.Terminate;
   Exit;
  end;
  MainForm := TMainForm.Create(Application);
end.
</Code>
      <Child>
        <Main ImageIndex="1">
          <Object ClassName="TMainForm">object MainForm: TForm
  Left = 301
  Height = 600
  Hint = 'dimStat - DIM Statictics Utility.'
  Top = 159
  Width = 1100
  BorderWidth = 4
  Caption = 'MainForm'
  ClientHeight = 600
  ClientWidth = 1100
  Constraints.MinHeight = 600
  Constraints.MinWidth = 1100
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  ParentFont = True
  ShowHint = True
  LCLVersion = '2.2.6.0'
  object PanelMain: TPanel
    Left = 4
    Height = 592
    Top = 4
    Width = 1092
    Align = alClient
    BorderWidth = 4
    ClientHeight = 592
    ClientWidth = 1092
    TabOrder = 0
    object PageControlMain: TPageControl
      Left = 5
      Height = 582
      Top = 5
      Width = 1082
      ActivePage = TabSheetMain
      Align = alClient
      Images = DataModuleGuiResMain.ImageListMain32x32
      TabIndex = 0
      TabOrder = 0
      object TabSheetMain: TTabSheet
        Caption = 'Main  '
        ClientHeight = 538
        ClientWidth = 1072
        ImageIndex = 114
        object PanelMainContent: TPanel
          Left = 0
          Height = 472
          Top = 0
          Width = 1072
          Align = alClient
          BorderWidth = 4
          ClientHeight = 472
          ClientWidth = 1072
          TabOrder = 0
          object PanelDimStat: TPanel
            Left = 5
            Height = 150
            Top = 5
            Width = 1062
            Align = alTop
            BorderWidth = 4
            ClientHeight = 150
            ClientWidth = 1062
            TabOrder = 0
            object GroupBoxDimStat: TGroupBox
              Left = 5
              Height = 140
              Top = 5
              Width = 1052
              Align = alClient
              Caption = ' dimStat utility - Command Line Constructor '
              ClientHeight = 124
              ClientWidth = 1050
              TabOrder = 0
              object ScrollBoxDimStat: TScrollBox
                Left = 0
                Height = 102
                Top = 0
                Width = 1050
                HorzScrollBar.Page = 1044
                VertScrollBar.Page = 91
                Align = alClient
                ClientHeight = 100
                ClientWidth = 1048
                TabOrder = 0
                object LabelDimStat: TLabel
                  Left = 92
                  Height = 15
                  Hint = 'dimStat - DIM Statictics utility.'
                  Top = 4
                  Width = 56
                  Caption = 'dimStat'
                  ParentColor = False
                end
                object CheckBoxDimStatOptDns: TCheckBox
                  Left = 164
                  Height = 21
                  Hint = 'dimStat - option to use specified DIM DNS NODE.'
                  Top = 0
                  Width = 64
                  Caption = '--dns'
                  TabOrder = 0
                end
                object ComboBoxDimStatParDns: TComboBox
                  Left = 88
                  Height = 25
                  Hint = 'dimStat - name of uses DIM DNS NODE.'
                  Top = 20
                  Width = 152
                  DropDownCount = 24
                  ItemHeight = 0
                  ItemIndex = 0
                  Items.Strings = (
                    'localhost'
                  )
                  TabOrder = 1
                  Text = 'localhost'
                end
                object CheckBoxDimStatOptVerbose: TCheckBox
                  Left = 248
                  Height = 21
                  Hint = 'dimStat - option to run verbose.'
                  Top = 50
                  Width = 96
                  Caption = '--verbose'
                  TabOrder = 11
                end
                object LabelDimStatAction: TLabel
                  Left = 248
                  Height = 15
                  Hint = 'dimStat - Action to execute.'
                  Top = 0
                  Width = 136
                  Caption = 'Action to execute'
                  ParentColor = False
                end
                object ComboBoxDimStatAction: TComboBox
                  Left = 248
                  Height = 27
                  Hint = 'dimStat - Action to execute.'
                  Top = 16
                  Width = 164
                  DropDownCount = 24
                  ItemHeight = 0
                  ItemIndex = 1
                  Items.Strings = (
                    '--version'
                    '--help'
                    '--running'
                    '--servers'
                    '--services'
                    '--serverclients'
                    '--serverservices'
                  )
                  Style = csDropDownList
                  TabOrder = 2
                  Text = '--help'
                end
                object LabelDimStatCmd: TLabel
                  Left = 88
                  Height = 15
                  Hint = 'dimStat - CMD options to run with.'
                  Top = 52
                  Width = 64
                  Caption = 'run with'
                  ParentColor = False
                end
                object ComboBoxDimStatCmd: TComboBox
                  Left = 156
                  Height = 27
                  Hint = 'dimStat - CMD options to run with.'
                  Top = 44
                  Width = 84
                  DropDownCount = 24
                  ItemHeight = 0
                  ItemIndex = 2
                  Items.Strings = (
                    ''
                    'cmd /c'
                    'cmd /k'
                  )
                  Style = csDropDownList
                  TabOrder = 10
                  Text = 'cmd /k'
                end
                object LabelDimStatOptTarget: TLabel
                  Left = 420
                  Height = 15
                  Hint = 'dimStat - Action Target (service or server name).'
                  Top = 0
                  Width = 280
                  Caption = 'Action Target (service/server name)'
                  ParentColor = False
                end
                object ComboBoxDimStatTarget: TComboBox
                  Left = 420
                  Height = 25
                  Hint = 'dimStat - Action Target, i.e. name of service(s) or server(s).'
                  Top = 16
                  Width = 280
                  DropDownCount = 24
                  ItemHeight = 0
                  TabOrder = 3
                end
                object ComboBoxDimStatOptSort: TComboBox
                  Left = 532
                  Height = 25
                  Hint = 'dimStat - Sort result table by specified criteria.'
                  Top = 48
                  Width = 168
                  DropDownCount = 24
                  ItemHeight = 0
                  ItemIndex = 1
                  Items.Strings = (
                    '--sort-by-name'
                    '--sort-by-pollrate'
                    '--sort-by-byterate'
                    '--sort-by-pollcount'
                    '--sort-by-bytecount'
                  )
                  TabOrder = 14
                  Text = '--sort-by-pollrate'
                end
                object CheckBoxDimStatOptStat: TCheckBox
                  Left = 708
                  Height = 21
                  Hint = 'dimStat - Statictics collect option.'
                  Top = 0
                  Width = 72
                  Caption = '--stat'
                  TabOrder = 4
                end
                object ComboBoxDimStatParStat: TComboBox
                  Left = 708
                  Height = 25
                  Hint = 'dimStat - Statictics collect period, seconds.'
                  Top = 20
                  Width = 72
                  DropDownCount = 24
                  ItemHeight = 0
                  ItemIndex = 4
                  Items.Strings = (
                    '1'
                    '2'
                    '3'
                    '4'
                    '5'
                    '7'
                    '10'
                    '15'
                    '20'
                    '30'
                    '60'
                    '120'
                    '180'
                    '300'
                  )
                  TabOrder = 5
                  Text = '5'
                end
                object CheckBoxDimStatOptLoop: TCheckBox
                  Left = 788
                  Height = 21
                  Hint = 'dimStat - Option to repeat Statistics loop.'
                  Top = 0
                  Width = 72
                  Caption = '--loop'
                  Checked = True
                  State = cbChecked
                  TabOrder = 6
                end
                object ComboBoxDimStatParLoop: TComboBox
                  Left = 788
                  Height = 25
                  Hint = 'dimStat - Statictics loop count (0 = FOREVER).'
                  Top = 20
                  Width = 72
                  DropDownCount = 24
                  ItemHeight = 0
                  ItemIndex = 0
                  Items.Strings = (
                    '0'
                    '1'
                    '2'
                    '3'
                    '4'
                    '5'
                    '10'
                    '15'
                    '20'
                    '30'
                    '50'
                    '100'
                    '500'
                    '1000'
                  )
                  TabOrder = 7
                  Text = '0'
                end
                object CheckBoxDimStatOptTop: TCheckBox
                  Left = 868
                  Height = 21
                  Hint = 'dimStat - Option to print only Top items of table.'
                  Top = 0
                  Width = 64
                  Caption = '--top'
                  Checked = True
                  State = cbChecked
                  TabOrder = 8
                end
                object ComboBoxDimStatParTop: TComboBox
                  Left = 868
                  Height = 25
                  Hint = 'dimStat - Top number of lines to print.'
                  Top = 20
                  Width = 72
                  DropDownCount = 24
                  ItemHeight = 0
                  ItemIndex = 7
                  Items.Strings = (
                    '1'
                    '2'
                    '3'
                    '4'
                    '5'
                    '10'
                    '15'
                    '20'
                    '25'
                    '30'
                    '40'
                    '50'
                    '75'
                    '100'
                  )
                  TabOrder = 9
                  Text = '20'
                end
                object BitBtnDimStatCopyCmdLine: TBitBtn
                  Left = 4
                  Height = 30
                  Hint = 'dimStat - Copy Command Line to "User command to send".'
                  Top = 44
                  Width = 75
                  Action = ActionDimStatCopyCmdLine
                  Images = DataModuleGuiResMain.ImageListMain16x16
                  ImageIndex = 62
                  TabOrder = 16
                end
                object CheckBoxDimStatOptNohead: TCheckBox
                  Left = 704
                  Height = 21
                  Hint = 'dimStat - option print tables without headers.'
                  Top = 50
                  Width = 88
                  Caption = '--hohead'
                  TabOrder = 15
                end
                object CheckBoxDimStatOptNostderr: TCheckBox
                  Left = 344
                  Height = 21
                  Hint = 'dimStat - option don`t use stderr to print errors.'
                  Top = 50
                  Width = 104
                  Caption = '--nostderr'
                  Checked = True
                  State = cbChecked
                  TabOrder = 12
                end
                object CheckBoxDimStatOptSort: TCheckBox
                  Left = 456
                  Height = 21
                  Hint = 'dimStat - option to Sort Table by Name or Rate.'
                  Top = 50
                  Width = 72
                  Caption = '--sort'
                  Checked = True
                  State = cbChecked
                  TabOrder = 13
                end
                object CheckBoxDimStatOptTimeout: TCheckBox
                  Left = 948
                  Height = 21
                  Hint = 'dimStat - option to set Timeout for DIM requests.'
                  Top = 0
                  Width = 96
                  Caption = '--timeout'
                  TabOrder = 17
                end
                object ComboBoxDimStatParTimeout: TComboBox
                  Left = 948
                  Height = 25
                  Hint = 'dimStat - Timeout for DIM requests, sec.'
                  Top = 20
                  Width = 60
                  ItemHeight = 0
                  ItemIndex = 4
                  Items.Strings = (
                    '1'
                    '2'
                    '3'
                    '4'
                    '5'
                    '7'
                    '10'
                    '15'
                    '20'
                    '25'
                    '30'
                    '60'
                  )
                  TabOrder = 18
                  Text = '5'
                end
                object LabelDimStatSec: TLabel
                  Left = 1012
                  Height = 15
                  Top = 24
                  Width = 24
                  Caption = 'sec'
                  ParentColor = False
                end
                object CheckBoxDimStatOptBufferSize: TCheckBox
                  Left = 812
                  Height = 21
                  Hint = 'dimStat - option to set Buffer Size for StdOut.'
                  Top = 50
                  Width = 128
                  Caption = '--buffer-size'
                  TabOrder = 19
                end
                object ComboBoxDimStatParBufferSize: TComboBox
                  Left = 948
                  Height = 25
                  Hint = 'dimStat - Buffer Size for StdOut, kB.'
                  Top = 48
                  Width = 68
                  ItemHeight = 0
                  ItemIndex = 8
                  Items.Strings = (
                    '1'
                    '2'
                    '4'
                    '8'
                    '16'
                    '32'
                    '64'
                    '128'
                    '256'
                    '512'
                    '1024'
                    '2048'
                    '4096'
                    '8192'
                  )
                  TabOrder = 20
                  Text = '256'
                end
                object LabelDimStatKb: TLabel
                  Left = 1020
                  Height = 15
                  Top = 52
                  Width = 16
                  Caption = 'kB'
                  ParentColor = False
                end
                object LabelDimStatCmdLine: TLabel
                  Left = 4
                  Height = 15
                  Hint = 'dimStat - Command Line to run.'
                  Top = 76
                  Width = 160
                  Caption = 'Command Line to run:'
                  Color = clInfoBk
                  ParentColor = False
                  Transparent = False
                end
                object ImageDimLogo: TImage
                  Left = 44
                  Height = 32
                  Hint = 'DIM home site: http://dim.web.cern.ch'
                  Top = 8
                  Width = 32
                  OnClick = ImageDimLogoClick
                  Picture.Data = {
[encoded data, 19635 characters]
                    000000000000020200000000000002020000000000000202
                  }
                  Stretch = True
                end
                object ImageCernLogo: TImage
                  Left = 8
                  Height = 32
                  Hint = 'CERN home site: http://cern.ch'
                  Top = 8
                  Width = 32
                  OnClick = ImageCernLogoClick
                  Picture.Data = {
[encoded data, 6460 characters]
                    8C1A1870A89CF83FD86195CFDF2183520000000049454E44AE426082
                  }
                  Stretch = True
                end
              end
              object PanelDimStatCmdLine: TPanel
                Left = 0
                Height = 22
                Hint = 'dimStat - Command Line to run.'
                Top = 102
                Width = 1050
                Align = alBottom
                Alignment = taLeftJustify
                BevelOuter = bvLowered
                BorderWidth = 4
                BorderStyle = bsSingle
                Caption = '@run dimstat'
                Color = clInfoBk
                ParentColor = False
                TabOrder = 1
                OnClick = ActionDimStatCopyCmdLineExecute
              end
            end
          end
          object PanelMainResult: TPanel
            Left = 5
            Height = 312
            Top = 155
            Width = 1062
            Align = alClient
            BorderWidth = 4
            ClientHeight = 312
            ClientWidth = 1062
            TabOrder = 1
            object PanelMainResultButtons: TPanel
              Left = 1015
              Height = 276
              Top = 31
              Width = 42
              Align = alRight
              BorderWidth = 4
              ClientHeight = 276
              ClientWidth = 42
              TabOrder = 0
              object BitBtnMainResultClear: TBitBtn
                Left = 4
                Height = 30
                Hint = 'Result - Clear Text.'
                Top = 140
                Width = 32
                Action = ActionMainResultClear
                Images = DataModuleGuiResMain.ImageListMain16x16
                ImageIndex = 23
                OnClick = BitBtnMainResultClearClick
                TabOrder = 4
              end
              object BitBtnMainResultCopy: TBitBtn
                Left = 4
                Height = 30
                Hint = 'Result - Copy Text to Clipboard.'
                Top = 76
                Width = 32
                Action = ActionMainResultCopy
                Images = DataModuleGuiResMain.ImageListMain16x16
                ImageIndex = 25
                TabOrder = 2
              end
              object BitBtnMainResultSelectAll: TBitBtn
                Left = 4
                Height = 30
                Top = 4
                Width = 32
                Action = ActionMainResultSelectAll
                Images = DataModuleGuiResMain.ImageListMain16x16
                ImageIndex = 33
                TabOrder = 0
              end
              object BitBtnMainResultSelectNone: TBitBtn
                Left = 4
                Height = 30
                Top = 36
                Width = 32
                Action = ActionMainResultSelectNone
                Images = DataModuleGuiResMain.ImageListMain16x16
                ImageIndex = 34
                TabOrder = 1
              end
              object BitBtnMainResultCut: TBitBtn
                Left = 4
                Height = 30
                Hint = 'Result - Cut Text to Clipboard.'
                Top = 108
                Width = 32
                Action = ActionMainResultCut
                Images = DataModuleGuiResMain.ImageListMain16x16
                ImageIndex = 24
                TabOrder = 3
              end
              object BitBtnMainResultFontInc: TBitBtn
                Left = 4
                Height = 30
                Top = 176
                Width = 32
                Action = ActionMainResultFontInc
                Anchors = [akLeft, akBottom]
                Images = DataModuleGuiResMain.ImageListMain16x16
                ImageIndex = 57
                TabOrder = 5
              end
              object BitBtnMainResultFontDec: TBitBtn
                Left = 4
                Height = 30
                Top = 240
                Width = 32
                Action = ActionMainResultFontDec
                Anchors = [akLeft, akBottom]
                Images = DataModuleGuiResMain.ImageListMain16x16
                ImageIndex = 58
                OnClick = BitBtn1Click
                TabOrder = 7
              end
              object BitBtnMainResultFontDef: TBitBtn
                Left = 4
                Height = 30
                Hint = 'Result - Font Size Default.'
                Top = 208
                Width = 32
                Action = ActionMainResultFontDef
                Anchors = [akLeft, akBottom]
                Images = DataModuleGuiResMain.ImageListMain16x16
                ImageIndex = 83
                TabOrder = 6
              end
            end
            object MemoMainResult: TMemo
              Left = 5
              Height = 276
              Hint = 'dimStat - Result of execution (status messages and output text).'
              Top = 31
              Width = 1010
              Align = alClient
              Color = clInfoBk
              HideSelection = False
              ReadOnly = True
              ScrollBars = ssAutoBoth
              TabOrder = 1
              WordWrap = False
            end
            object PanelMainResultTitle: TPanel
              Left = 5
              Height = 26
              Hint = 'dimStat - Result of execution.'
              Top = 5
              Width = 1052
              Align = alTop
              Alignment = taLeftJustify
              BorderWidth = 4
              Caption = 'Result:'
              ClientHeight = 26
              ClientWidth = 1052
              ParentColor = False
              TabOrder = 2
              object LabelDimStatRunStatus: TLabel
                Left = 96
                Height = 15
                Hint = 'dimStat - number of running instances.'
                Top = 4
                Width = 248
                Caption = ' 0 dimStat instance(s) running '
                Color = clInfoBk
                ParentColor = False
                Transparent = False
              end
            end
          end
        end
        object PanelMainButtons: TPanel
          Left = 0
          Height = 66
          Top = 472
          Width = 1072
          Align = alBottom
          BorderWidth = 8
          ClientHeight = 66
          ClientWidth = 1072
          TabOrder = 1
          object LabelDimStatSend: TLabel
            Left = 8
            Height = 15
            Hint = 'User Command to Send to Parent CRW-DAQ Main Console.'
            Top = 11
            Width = 160
            Anchors = [akLeft, akBottom]
            Caption = 'User command to send'
            ParentColor = False
          end
          object EditDimStatSend: TEdit
            Left = 8
            Height = 27
            Hint = 'Input command to send to CRW-DAQ console.'
            Top = 23
            Width = 566
            Anchors = [akLeft, akRight, akBottom]
            TabOrder = 0
            Text = '@echo Hello, CRW-DAQ'
          end
          object BitBtnDimStatSend: TBitBtn
            Left = 582
            Height = 46
            Hint = 'dimStat - Send Command to CRW-DAQ Main Console.'
            Top = 12
            Width = 91
            Action = ActionDimStatSend
            Anchors = [akRight, akBottom]
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 59
            TabOrder = 1
          end
          object BitBtnDimStatRun: TBitBtn
            Left = 680
            Height = 46
            Hint = 'dimStat - Run Command specified above.'
            Top = 12
            Width = 91
            Action = ActionDimStatRun
            Anchors = [akRight, akBottom]
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 114
            TabOrder = 2
          end
          object BitBtnMainProgramExit: TBitBtn
            Left = 872
            Height = 46
            Top = 12
            Width = 91
            Action = ActionMainProgramExit
            Anchors = [akRight, akBottom]
            ModalResult = 11
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 113
            TabOrder = 4
          end
          object BitBtnMainParentShow: TBitBtn
            Left = 968
            Height = 46
            Top = 12
            Width = 91
            Action = ActionMainParentShow
            Anchors = [akRight, akBottom]
            ModalResult = 11
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 234
            TabOrder = 5
          end
          object BitBtnDimStatStop: TBitBtn
            Left = 777
            Height = 46
            Top = 12
            Width = 91
            Action = ActionDimStatStop
            Anchors = [akRight, akBottom]
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 115
            TabOrder = 3
          end
        end
      end
      object TabSheetCommonParams: TTabSheet
        Hint = 'Common parameters (memory buffers, timeouts etc).'
        Caption = 'Params'
        ClientHeight = 538
        ClientWidth = 1072
        ImageIndex = 161
        object PanelCommonParams: TPanel
          Left = 0
          Height = 538
          Top = 0
          Width = 1072
          Align = alClient
          BorderWidth = 4
          ClientHeight = 538
          ClientWidth = 1072
          TabOrder = 0
          object GroupBoxExecParams: TGroupBox
            Left = 5
            Height = 97
            Top = 5
            Width = 1062
            Align = alTop
            Caption = ' Exec Parameters '
            ClientHeight = 81
            ClientWidth = 1060
            TabOrder = 0
            object ScrollBoxExecParams: TScrollBox
              Left = 0
              Height = 81
              Top = 0
              Width = 1060
              HorzScrollBar.Page = 704
              VertScrollBar.Page = 65
              Align = alClient
              ClientHeight = 77
              ClientWidth = 1056
              TabOrder = 0
              object LabelDefExecBuffKb: TLabel
                Left = 12
                Height = 15
                Hint = 'Default I/O Buffer for Exec (to run tasks with normal output), kB.'
                Top = 12
                Width = 248
                Caption = 'Default I/O Buffer for Exec, Kb'
                ParentColor = False
              end
              object ComboBoxDefExecBuffKb: TComboBox
                Left = 276
                Height = 23
                Hint = 'Default I/O Buffer for Exec (to run tasks with normal output), kB.'
                Top = 8
                Width = 100
                DropDownCount = 24
                ItemHeight = 0
                ItemIndex = 8
                Items.Strings = (
                  '1'
                  '2'
                  '4'
                  '8'
                  '16'
                  '32'
                  '64'
                  '128'
                  '256'
                  '512'
                  '1024'
                  '2048'
                  '4096'
                  '8192'
                  '16384'
                  '32768'
                  '65536'
                )
                OnChange = ComboBoxDefExecBuffKbChange
                Style = csDropDownList
                TabOrder = 0
                Text = '256'
              end
              object LabelBigExecBuffKb: TLabel
                Left = 12
                Height = 15
                Hint = 'BigSize I/O Buffer for Exec (to run tasks with big output), kB.'
                Top = 44
                Width = 248
                Caption = 'BigSize I/O Buffer for Exec, kB'
                ParentColor = False
              end
              object ComboBoxBigExecBuffKb: TComboBox
                Left = 276
                Height = 23
                Hint = 'BigSize I/O Buffer for Exec (to run tasks with big output), kB.'
                Top = 40
                Width = 100
                ItemHeight = 0
                ItemIndex = 8
                Items.Strings = (
                  '64'
                  '128'
                  '256'
                  '512'
                  '1024'
                  '2048'
                  '4096'
                  '8192'
                  '16384'
                  '32768'
                  '65536'
                )
                Style = csDropDownList
                TabOrder = 1
                Text = '16384'
              end
              object LabelDefExecTimeOut: TLabel
                Left = 396
                Height = 15
                Hint = 'Default Timeout for Exec (to run tasks with normal output), ms.'
                Top = 12
                Width = 192
                Caption = 'Default Exec TimeOut, ms'
                ParentColor = False
              end
              object ComboBoxDefExecTimeOut: TComboBox
                Left = 604
                Height = 25
                Hint = 'Default Timeout for Exec (to run tasks with normal output), ms.'
                Top = 8
                Width = 100
                ItemHeight = 0
                ItemIndex = 4
                Items.Strings = (
                  '1000'
                  '2000'
                  '3000'
                  '4000'
                  '5000'
                  '7000'
                  '10000'
                  '15000'
                  '20000'
                  '30000'
                  '45000'
                  '60000'
                  '90000'
                  '120000'
                  '180000'
                  '300000'
                )
                TabOrder = 2
                Text = '5000'
              end
              object LabelBigExecTimeOut: TLabel
                Left = 396
                Height = 15
                Hint = 'BigSize Timeout for Exec (to run tasks with big output), ms.'
                Top = 44
                Width = 192
                Caption = 'BigSize Exec TimeOut, ms'
                ParentColor = False
              end
              object ComboBoxBigExecTimeOut: TComboBox
                Left = 604
                Height = 25
                Hint = 'BigSize Timeout for Exec (to run tasks with big output), ms.'
                Top = 40
                Width = 100
                ItemHeight = 0
                ItemIndex = 7
                Items.Strings = (
                  '1000'
                  '2000'
                  '3000'
                  '4000'
                  '5000'
                  '7000'
                  '10000'
                  '15000'
                  '20000'
                  '30000'
                  '45000'
                  '60000'
                  '90000'
                  '120000'
                  '180000'
                  '300000'
                )
                TabOrder = 3
                Text = '15000'
              end
            end
          end
        end
      end
      object TabSheetLogEvents: TTabSheet
        BorderWidth = 8
        Caption = 'Log  '
        ClientHeight = 538
        ClientWidth = 1072
        ImageIndex = 168
        object PanelLogEventsContent: TPanel
          Left = 0
          Height = 476
          Top = 0
          Width = 1072
          Align = alClient
          BorderWidth = 8
          ClientHeight = 476
          ClientWidth = 1072
          TabOrder = 0
          object LabelLogEvents: TLabel
            Left = 9
            Height = 15
            Top = 9
            Width = 1054
            Align = alTop
            Caption = 'Event log (list of events occurred):'
            ParentColor = False
          end
          object MemoLogEvents: TMemo
            Left = 9
            Height = 426
            Top = 24
            Width = 1054
            Align = alClient
            Color = clInfoBk
            ReadOnly = True
            ScrollBars = ssAutoBoth
            TabOrder = 0
            WordWrap = False
          end
          object StatusBarLogEvents: TStatusBar
            Left = 9
            Height = 17
            Top = 450
            Width = 1054
            Panels = &lt;&gt;
          end
        end
        object PanelLogEventsButtons: TPanel
          Left = 0
          Height = 62
          Top = 476
          Width = 1072
          Align = alBottom
          BorderWidth = 8
          ClientHeight = 62
          ClientWidth = 1072
          TabOrder = 1
          object BitBtnLogEventsTest: TBitBtn
            Left = 781
            Height = 46
            Hint = 'Raise exception for test.'
            Top = 8
            Width = 91
            Anchors = [akTop, akRight]
            Caption = ' Test'
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 115
            OnClick = BitBtnLogEventsTestClick
            TabOrder = 0
          end
          object BitBtnLogEventsClear: TBitBtn
            Left = 877
            Height = 46
            Top = 8
            Width = 91
            Action = ActionMainLogEventsClear
            Anchors = [akTop, akRight]
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 119
            TabOrder = 1
          end
          object BitBtnLogEventsGoBack: TBitBtn
            Left = 973
            Height = 46
            Top = 8
            Width = 91
            Action = ActionMainLogEventsGoBack
            Anchors = [akTop, akRight]
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 59
            TabOrder = 2
          end
          object LabelMainListSysInfo: TLabel
            Left = 8
            Height = 15
            Top = 8
            Width = 88
            Caption = 'Info topic:'
            ParentColor = False
          end
          object ComboBoxMainListSysInfo: TComboBox
            Left = 8
            Height = 27
            Top = 28
            Width = 182
            DropDownCount = 24
            ItemHeight = 0
            ItemIndex = 0
            Items.Strings = (
              'list environ'
              'list session'
              'list modules 0'
              'list process 0 0 *'
              'list windows 0 * *'
            )
            TabOrder = 3
            Text = 'list environ'
          end
          object LabelMainListSysInfoTimeOut: TLabel
            Left = 190
            Height = 15
            Top = 8
            Width = 56
            Caption = 'TimeOut'
            ParentColor = False
          end
          object SpinEditMainListSysInfoTimeOut: TSpinEdit
            Left = 190
            Height = 25
            Hint = 'Timeout for execution, sec.'
            Top = 26
            Width = 54
            MaxValue = 60
            MinValue = 1
            TabOrder = 4
            Value = 5
          end
          object BitBtnMainListSysInfo: TBitBtn
            Left = 246
            Height = 46
            Top = 8
            Width = 91
            Action = ActionMainListSysInfo
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 124
            TabOrder = 5
          end
        end
      end
    end
  end
  object TimerLogEventsUpdater: TTimer
    OnTimer = TimerLogEventsUpdaterTimer
    Left = 356
  end
  object ActionListMain: TActionList
    Images = DataModuleGuiResMain.ImageListMain32x32
    Left = 320
    object ActionMainProgramExit: TAction
      Caption = 'Exit'
      Hint = 'Exit program.'
      ImageIndex = 113
      OnExecute = ActionMainExitExecute
    end
    object ActionMainParentShow: TAction
      Caption = 'Show'
      Hint = 'Open (activate) patent Crw32 program window.'
      ImageIndex = 234
      OnExecute = ActionMainParentShowExecute
    end
    object ActionMainFormShow: TAction
      Caption = 'Show MainForm'
      ImageIndex = 164
      OnExecute = ActionMainFormShowExecute
    end
    object ActionDimStatSend: TAction
      Caption = 'Send'
      Hint = 'Send command to CRW-DAQ  console.'
      ImageIndex = 59
      OnExecute = ActionDimStatSendExecute
    end
    object ActionDimStatRun: TAction
      Caption = 'Run'
      Hint = 'Run command from Crw32.ini list.'
      ImageIndex = 114
      OnExecute = ActionDimStatRunExecute
    end
    object ActionDimStatStop: TAction
      Caption = 'Stop'
      Hint = 'dimStat - Stop all running instances.'
      ImageIndex = 115
      OnExecute = ActionDimStatStopExecute
    end
    object ActionMainLogEventsClear: TAction
      Caption = 'Clear'
      Hint = 'Clear event log.'
      ImageIndex = 119
      OnExecute = ActionMainLogEventsClearExecute
    end
    object ActionMainLogEventsGoBack: TAction
      Caption = 'Back'
      Hint = 'Go back to main page.'
      ImageIndex = 59
      OnExecute = ActionMainLogEventsGoBackExecute
    end
    object ActionDimStatCopyCmdLine: TAction
      Caption = 'Copy'
      Hint = 'dimStat - Copy command line to "User command to send".'
      ImageIndex = 62
      OnExecute = ActionDimStatCopyCmdLineExecute
    end
    object ActionMainResultSelectAll: TAction
      Hint = 'Result - Select All.'
      ImageIndex = 33
      OnExecute = ActionMainResultSelectAllExecute
    end
    object ActionMainResultSelectNone: TAction
      Hint = 'Result - No Selection.'
      ImageIndex = 34
      OnExecute = ActionMainResultSelectNoneExecute
    end
    object ActionMainResultClear: TAction
      Hint = 'Clear Result.'
      ImageIndex = 23
      OnExecute = ActionMainResultClearExecute
    end
    object ActionMainResultCut: TAction
      Hint = 'Result - Cut text to clipboard.'
      ImageIndex = 48
      OnExecute = ActionMainResultCutExecute
    end
    object ActionMainResultCopy: TAction
      Hint = 'Copy Result selection.'
      ImageIndex = 25
      OnExecute = ActionMainResultCopyExecute
    end
    object ActionMainResultFontInc: TAction
      Hint = 'Result - Font Size Increment.'
      ImageIndex = 57
      OnExecute = ActionMainResultFontIncExecute
    end
    object ActionMainResultFontDec: TAction
      Hint = 'Result - Font Size Decrement.'
      ImageIndex = 58
      OnExecute = ActionMainResultFontDecExecute
    end
    object ActionMainResultFontDef: TAction
      Hint = 'Result - Default Font Size.'
      ImageIndex = 83
      OnExecute = ActionMainResultFontDefExecute
    end
    object ActionMainListSysInfo: TAction
      Caption = 'Info'
      Hint = 'Print system information on specified topic.'
      ImageIndex = 124
      OnExecute = ActionMainListSysInfoExecute
    end
  end
  object TrayIconMain: TTrayIcon
    PopUpMenu = PopupMenuTray
    Icon.Data = {
[encoded data, 16401 characters]
      020200000000000002020000000000000202
    }
    OnClick = TrayIconMainClick
    OnDblClick = TrayIconMainDblClick
    Left = 392
  end
  object PopupMenuTray: TPopupMenu
    Images = DataModuleGuiResMain.ImageListMain32x32
    Left = 432
    object MenuItemTrayFormShow: TMenuItem
      Action = ActionMainFormShow
    end
    object MenuItemTrayParentShow: TMenuItem
      Action = ActionMainParentShow
    end
    object N1: TMenuItem
      Caption = '-'
    end
    object MenuItemTrayProgramExit: TMenuItem
      Action = ActionMainProgramExit
    end
  end
  object TimerDimStatUpdater: TTimer
    OnTimer = TimerDimStatUpdaterTimer
    Left = 472
  end
  object TimerTaskPoll: TTimer
    Interval = 100
    OnTimer = TimerTaskPollTimer
    Left = 512
  end
end
</Object>
          <Code>unit Main;

uses  dpCmdArgs,dpSystem,dpSysUtils,dpVbs,dpWindows,dpGuiUtils,
      dpCrwDaqSys,dpDaqConfig,dpAntiZombie,dpGuiResMain,dpTask,
      dpLinux;

type
  TMainForm = class(TForm)
    TimerLogEventsUpdater: TTimer;
    TimerDimStatUpdater: TTimer;
    TimerTaskPoll: TTimer;
    // Actions
    ActionListMain: TActionList;
    ActionMainProgramExit: TAction;
    ActionMainParentShow: TAction;
    ActionMainFormShow: TAction;
    ActionDimStatCopyCmdLine: TAction;
    ActionDimStatSend: TAction;
    ActionDimStatRun: TAction;
    ActionDimStatStop: TAction;
    ActionMainResultSelectAll: TAction;
    ActionMainResultSelectNone: TAction;
    ActionMainResultCut: TAction;
    ActionMainResultClear: TAction;
    ActionMainResultCopy: TAction;
    ActionMainResultFontDef: TAction;
    ActionMainResultFontInc: TAction;
    ActionMainResultFontDec: TAction;
    ActionMainLogEventsClear: TAction;
    ActionMainLogEventsGoBack: TAction;
    // TrayIcon
    TrayIconMain: TTrayIcon;
    PopupMenuTray: TPopupMenu;
    MenuItemTrayFormShow: TMenuItem;
    MenuItemTrayParentShow: TMenuItem;
    MenuItemTrayProgramExit: TMenuItem;
    MenuItemTrayProgramExitSeparator: TMenuItem;
    // Main Panel
    PanelMain: TPanel;
    // Main TabSheep
    TabSheetMain: TTabSheet;
    PageControlMain: TPageControl;
    PanelMainContent: TPanel;
    // PanelMainButtons
    PanelMainButtons: TPanel;
    LabelDimStatSend: TLabel;
    EditDimStatSend: TEdit;
    BitBtnDimStatSend: TBitBtn;
    BitBtnDimStatRun: TBitBtn;
    BitBtnDimStatStop: TBitBtn;
    BitBtnMainProgramExit: TBitBtn;
    BitBtnMainParentShow: TBitBtn;
    // LogEvents TabSheet
    TabSheetLogEvents: TTabSheet;
    PanelLogEventsContent: TPanel;
    LabelLogEvents: TLabel;
    MemoLogEvents: TMemo;
    StatusBarLogEvents: TStatusBar;
    PanelLogEventsButtons: TPanel;
    BitBtnLogEventsTest: TBitBtn;
    BitBtnLogEventsClear: TBitBtn;
    BitBtnLogEventsGoBack: TBitBtn;
    // Panel DimStat
    PanelDimStat: TPanel;
    GroupBoxDimStat: TGroupBox;
    PanelMainResult: TPanel;
    PanelMainResultButtons: TPanel;
    MemoMainResult: TMemo;
    ScrollBoxDimStat: TScrollBox;
    BitBtnDimStatCopyCmdLine: TBitBtn;
    LabelDimStat: TLabel;
    CheckBoxDimStatOptDns: TCheckBox;
    ComboBoxDimStatParDns: TComboBox;
    CheckBoxDimStatOptVerbose: TCheckBox;
    CheckBoxDimStatOptNohead: TCheckBox;
    CheckBoxDimStatOptNostderr: TCheckBox;
    LabelDimStatAction: TLabel;
    ComboBoxDimStatAction: TComboBox;
    LabelDimStatCmd: TLabel;
    ComboBoxDimStatCmd: TComboBox;
    LabelDimStatOptTarget: TLabel;
    ComboBoxDimStatTarget: TComboBox;
    ComboBoxDimStatOptSort: TComboBox;
    CheckBoxDimStatOptStat: TCheckBox;
    ComboBoxDimStatParStat: TComboBox;
    CheckBoxDimStatOptLoop: TCheckBox;
    ComboBoxDimStatParLoop: TComboBox;
    CheckBoxDimStatOptTop: TCheckBox;
    ComboBoxDimStatParTop: TComboBox;
    CheckBoxDimStatOptSort: TCheckBox;
    CheckBoxDimStatOptTimeout: TCheckBox;
    ComboBoxDimStatParTimeout: TComboBox;
    LabelDimStatSec: TLabel;
    CheckBoxDimStatOptBufferSize: TCheckBox;
    ComboBoxDimStatParBufferSize: TComboBox;
    LabelDimStatKb: TLabel;
    PanelDimStatCmdLine: TPanel;
    LabelDimStatCmdLine: TLabel;
    // Panel MainResult
    PanelMainResultTitle: TPanel;
    LabelDimStatRunStatus: TLabel;
    BitBtnMainResultClear: TBitBtn;
    BitBtnMainResultCopy: TBitBtn;
    BitBtnMainResultSelectAll: TBitBtn;
    BitBtnMainResultSelectNone: TBitBtn;
    BitBtnMainResultCut: TBitBtn;
    BitBtnMainResultFontInc: TBitBtn;
    BitBtnMainResultFontDec: TBitBtn;
    BitBtnMainResultFontDef: TBitBtn;
    TabSheetCommonParams: TTabSheet;
    PanelCommonParams: TPanel;
    GroupBoxExecParams: TGroupBox;
    ScrollBoxExecParams: TScrollBox;
    LabelDefExecBuffKb: TLabel;
    ComboBoxDefExecBuffKb: TComboBox;
    LabelBigExecBuffKb: TLabel;
    ComboBoxBigExecBuffKb: TComboBox;
    LabelDefExecTimeOut: TLabel;
    ComboBoxDefExecTimeOut: TComboBox;
    LabelBigExecTimeOut: TLabel;
    ComboBoxBigExecTimeOut: TComboBox;
    ActionMainListSysInfo: TAction;
    LabelMainListSysInfo: TLabel;
    ComboBoxMainListSysInfo: TComboBox;
    LabelMainListSysInfoTimeOut: TLabel;
    SpinEditMainListSysInfoTimeOut: TSpinEdit;
    BitBtnMainListSysInfo: TBitBtn;
    ImageDimLogo: TImage;
    ImageCernLogo: TImage;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure TrayIconMainClick(Sender: TObject);
    procedure TrayIconMainDblClick(Sender: TObject);
    procedure TimerLogEventsUpdaterTimer(Sender: TObject);
    procedure TimerDimStatUpdaterTimer(Sender: TObject);
    procedure TimerTaskPollTimer(Sender: TObject);
    procedure ActionMainExitExecute(Sender: TObject);
    procedure ActionMainParentShowExecute(Sender: TObject);
    procedure ActionMainFormShowExecute(Sender: TObject);
    procedure ActionMainResultClearExecute(Sender: TObject);
    procedure ActionMainResultCopyExecute(Sender: TObject);
    procedure ActionMainResultSelectAllExecute(Sender: TObject);
    procedure ActionMainResultSelectNoneExecute(Sender: TObject);
    procedure ActionMainResultCutExecute(Sender: TObject);
    procedure ActionDimStatCopyCmdLineExecute(Sender: TObject);
    procedure ActionDimStatSendExecute(Sender: TObject);
    procedure ActionDimStatRunExecute(Sender: TObject);
    procedure ActionDimStatStopExecute(Sender: TObject);
    procedure ActionMainLogEventsClearExecute(Sender: TObject);
    procedure ActionMainLogEventsGoBackExecute(Sender: TObject);
    procedure ActionMainListSysInfoExecute(Sender: TObject);
    procedure BitBtnLogEventsTestClick(Sender: TObject);
    procedure ActionMainResultFontDecExecute(Sender: TObject);
    procedure ActionMainResultFontIncExecute(Sender: TObject);
    procedure ActionMainResultFontDefExecute(Sender: TObject);
    procedure ImageDimLogoClick(Sender: TObject);
    procedure ImageCernLogoClick(Sender: TObject);
   private
   myDIM_DNS_NODE : String;
   myComputerName : String;
   myLastAction   : String;
   myLastOptStat  : Integer;
   myTaskPollNum  : Cardinal;
   myDimStatTids  : array[0..255] of Boolean;
   myDimStatStop  : array[0..255] of Double;
  protected
  public
    property  DIM_DNS_NODE:String read myDIM_DNS_NODE;
    property  ComputerName:String read myComputerName;
    function  OPT_VERBOSE(Prefix:String=''):String;
    function  OPT_NOSTDERR(Prefix:String=''):String;
    function  OPT_BUFFER_SIZE(Prefix:String=''):String;
    function  OPT_TIMEOUT(Prefix:String=''):String;
    function  OPT_DNS(Prefix:String=''):String;
    function  OPT_ACTION(Prefix:String=''):String;
    function  OPT_TARGET(Prefix:String=''):String;
    function  OPT_NOHEAD(Prefix:String=''):String;
    function  OPT_SORT(Prefix:String=''):String;
    function  OPT_STAT(Prefix:String=''):String;
    function  OPT_LOOP(Prefix:String=''):String;
    function  OPT_TOP(Prefix:String=''):String;
    function  DefExecBuffKb:Integer;
    function  BigExecBuffKb:Integer;
    function  DefExecTimeOut:Integer;
    function  BigExecTimeOut:Integer;
    procedure ShowTrayIcon;
    procedure AdjustComponents;
    function  GetCommonProgramFilesDimBin:String;
    procedure BugReport(E:Exception; Sender:TObject; Where:String);
    procedure SendCommandToCrwDaq(S:String; Activate:Boolean=true);
    procedure PostCommandToCrwDaq(S:String);
    procedure UpdateState(flags:Integer);
    function  dimStatExe(Mode:Integer=0):String;
    function  GetDimStatCmdLine(NoCmd:Boolean=false):String;
    function  Exec(cmd:String; timeout:Integer=0; BuffSizeKb:Integer=0):String;
    function  GetDimStatServers(aList:TStrings=nil):String;
    function  GetDimStatServices(aList:TStrings=nil):String;
    procedure LogResults(When:TDateTime; S:String);
    procedure AddResults(When:TDateTime; S:String);
    procedure Trouble(Msg:String);
    procedure Success(Msg:String);
    function  GetHostName:String;
    procedure DimStatRun;
    procedure DimStatStop;
    procedure DimStatKill;
    procedure DimStatPoll;
  end;

var MainForm: TMainForm;

//////////////////////////////////// UpdateState flags:
const us_Init        = $00000001; // Initialization
const us_Action      = $00000002; // Action changed
const us_Timer       = $00000004; // Timer poll
//////////////////////////////////// Exec params:
const MinExecBuffKb  = 1;         // Minimal Exec buffer, kB
const MaxExecBuffKb  = 1024*64;   // Maximal Exec buffer, kB
const DivExecBuffKb  = 256;       // Default Exec buffer init value, kB
const BivExecBuffKb  = 1024*16;   // Bigsize Exec buffer init value, kB
const MinExecTimeOut = 1000;      // Minimal Exec timeout, ms
const MaxExecTimeout = 1000*60*5; // Maximal Exec timeout, ms
const DivExecTimeout = 1000*5;    // Default Exec timeout init value, ms
const BivExecTimeout = 1000*15;   // Bigsize Exec timeout init value, ms
//////////////////////////////////// Task stop/kill params:
const DelayOnStop    = 1000;      // Delay on Stop tasks
const DelayOnKill    = 1000;      // Delay on Kill tasks
//////////////////////////////////// Font size params:
const MinFontSize    = 7;         // Minimal font size for MainResult
const DefFontSize    = 10;        // Default font size for MainResult
const MaxFontSize    = 32;        // Maximal font size for MainResult

implementation

procedure TMainForm.FormCreate(Sender: TObject);
begin
 try
  defIpcInit;
  defParamsInit;
  InitAppFolders;
  SetDefaultFontName(Font);
  InitAntiZombie(1000,true);
  Caption:=GetCrwDaqChildTitle;
  FormCenterToScreen(Self,0,0);
  SetButtonCursorToHandPoint(Self);
  StatusBarLogEvents.Font.Size:=10;
  PageControlMain.ActivePage:=TabSheetMain;
  LogEvents(Now,GetBriefEngineScriptInfo);
  LogEvents(Now,'Start.');
  AdjustComponents;
  ShowTrayIcon;
  if (CRW_DAQ_SYS_EXE_PID=0) then begin
   ActionMainParentShow.Enabled:=false;
   ActionDimStatSend.Enabled:=false;
   //RaiseException('Parent Crw32.exe process is not specified.');
  end;
 except
  on E:Exception do Self.BugReport(E,Self,'FormCreate');
 end;
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin
 DimStatKill;
end;

procedure TMainForm.ShowTrayIcon;
begin
 Application.Title:=GetScriptName;
 TrayIconMain.Visible:=true;
 TrayIconMain.Hint:=GetScriptName+LineEnding+Caption;
 MenuItemTrayFormShow.Caption:=FormatVar('Show Window [%s]',Caption);
 MenuItemTrayProgramExit.Caption:=FormatVar('Exit from [%s]',Caption);
 MenuItemTrayParentShow.Caption:=FormatVar('Show Parent Window [%s]',ParentCrwDaqTitle);
 HideApplicationIconFromTaskBar(true);
end;

procedure TMainForm.AdjustComponents;
var i:Integer; s:String;
begin
 myTaskPollNum:=0;
 for i:=0 to 255 do myDimStatTids[i]:=false;
 for i:=0 to 255 do myDimStatStop[i]:=0;
 MemoLogEvents.Font.Size:=10;
 MemoMainResult.Font.Size:=10;
 EditDimStatSend.Font.Size:=10;
 ScrollBoxDimStat.Font.Size:=10;
 PanelDimStatCmdLine.Font.Size:=10;
 LabelDimStatRunStatus.Font.Size:=10;
 ScrollBoxExecParams.Font.Size:=10;
 LabelDimStat.Font.Size:=12;
 LabelDimStat.Font.Color:=clMaroon;
 LabelDimStat.Font.Style:=LabelDimStat.Font.Style+[fsBold];
 UpdateState(us_Init+us_Action);
 SetDefaultSansFontName(LabelMainListSysInfoTimeOut.Font);
 if IsUnix then begin
  Width:=iMax(Width,1110);
  FormCenterToScreen(Self,0,0);
 end;
 if IsUnix then begin
  ComboBoxDimStatCmd.Items.Text:=' '+LineEnding
                                +'unix'+LineEnding
                                +'crwkit'+LineEnding
                                +'crwrun'+LineEnding;
  ComboBoxDimStatCmd.ItemIndex:=1;
 end;
 if IsWindows then begin
  if (CRW_DAQ_SYS_EXE_PID=0) then begin
   s:=GetCommonProgramFilesDimBin;
   if (s&lt;&gt;'') and DirectoryExists(s) then SetEnv('PATH',GetEnv('PATH')+';'+s);
  end;
 end;
 if FileExists(dimStatExe(1))
 or (FileSearch(dimStatExe(1),GetEnv('PATH'),false)&lt;&gt;'')
 then LogEvents(Now,'DimStat found: '+dimStatExe(1))
 else LogEvents(Now,'DimStat NOT found: '+dimStatExe(1));
end;

function TMainForm.GetCommonProgramFilesDimBin:String;
begin
 Result:=Trim(ExpEnv('%CommonProgramFiles%\CRW-DAQ\Resource\DimSite\dim\bin'));
 if (Result&lt;&gt;'') and DirectoryExists(Result) then Exit else Result:='';
 Result:=Trim(ExpEnv('%CommonProgramFiles(x86)%\CRW-DAQ\Resource\DimSite\dim\bin'));
 if (Result&lt;&gt;'') and DirectoryExists(Result) then Exit else Result:='';
 Result:=Trim(ExpEnv('%CommonProgramW6432%\CRW-DAQ\Resource\DimSite\dim\bin'));
 if (Result&lt;&gt;'') and DirectoryExists(Result) then Exit else Result:='';
end;

procedure TMainForm.BugReport(E:Exception; Sender:TObject; Where:String);
begin
 SystemBugReport(E,Sender,Where);
 PageControlMain.ActivePage:=TabSheetLogEvents;
end;

procedure TMainForm.SendCommandToCrwDaq(S:String; Activate:Boolean=true);
begin
 try
  if (CRW_DAQ_SYS_EXE_PID=0)
  then RaiseException('Parent Crw32.exe process is not specified.');
  S:=Trim(S); if (S='') then Exit;
  if (CRW_DAQ_SYS_EXE_PID=0) then Exit;
  if Activate then AppActivateByTitle(ParentCrwDaqTitle);
  if (Send2CrwDaq(CRW_DAQ_SYS_EXE_PID,S,Handle)=0)
  then LogEvents(Now,'Sent command: '+S)
  else LogEvents(Now,'Fail command: '+S);
  LogResults(Now,S);
 except
  on E:Exception do Self.BugReport(E,Self,'SendCommandToCrwDaq');
 end;
end;

procedure TMainForm.PostCommandToCrwDaq(S:String);
begin
 SendCommandToCrwDaq(S,false);
end;

procedure TMainForm.LogResults(When:TDateTime; S:String);
begin
 AddTextAsEventLog(MemoMainResult.Lines,When,S);
end;

procedure TMainForm.AddResults(When:TDateTime; S:String);
begin
 if (S='') then Exit;
 try
  MemoMainResult.Lines.BeginUpdate;
  StringsAppendFromText(MemoMainResult.Lines,S);
 finally
  MemoMainResult.Lines.EndUpdate;
 end;
 MemoMainResult.SelStart:=MaxInt;
end;

function TMainForm.Exec(cmd:String; timeout:Integer=0; BuffSizeKb:Integer=0):String;
var tid:Integer;
begin
 Result:='';
 try
  cmd:=Trim(cmd);
  if (Length(cmd)=0) then Exit;
  if (timeout&lt;MinExecTimeOut) then timeout:=DefExecTimeOut;
  if (BuffSizeKb&lt;MinExecBuffKb) then BuffSizeKb:=DefExecBuffKb;
  tid:=task_init(cmd);
  task_ctrl(tid,'Display=SW_HIDE');
  task_ctrl(tid,'StdInPipeSize='+IntToStr(1024*BuffSizeKb));
  task_ctrl(tid,'StdOutPipeSize='+IntToStr(1024*BuffSizeKb));
  task_ctrl(tid,'CodePage='+IntToStr(WinApi.GetACP));
  if task_run(tid) then begin
   task_wait(tid,timeout);
   Result:=task_recv(tid,MaxInt);
   if task_wait(tid,0) then task_kill(tid,1,0,500);
   if task_wait(tid,0) then task_kill(tid,0,0,0);
   Success(FormatVar('Exec[%d]: ',task_pid(tid))+cmd);
  end else begin
   Trouble('Could not Exec: '+cmd);
  end;
  task_free(tid);
 except
  on E:Exception do BugReport(E,Self,'Exec');
 end;
end;

procedure TMainForm.Trouble(Msg:String);
begin
 LogEvents(Now,Msg);
end;

procedure TMainForm.Success(Msg:String);
begin
 LogEvents(Now,Msg);
end;

procedure TMainForm.DimStatRun;
var cmd:String; tid,buffsize:Integer;
begin
 buffsize:=1024*DefExecBuffKb;
 cmd:=GetDimStatCmdLine(true);
 tid:=task_init('');
 if (tid=0) then begin
  LogResults(Now,FormatVar('Fail to init: %s',cmd));
  continue;
 end;
 task_ctrl(tid,FormatVar('CmdLine=%s',cmd));
 task_ctrl(tid,FormatVar('Display=%d',SW_SHOWMINNOACTIVE));
 task_ctrl(tid,FormatVar('HomeDir=%s',CRW_DAQ_SYS_HOME_DIR));
 task_ctrl(tid,FormatVar('ProcessPriority=%s','Normal'));
 task_ctrl(tid,FormatVar('StdInPipeSize=%d',buffsize));
 task_ctrl(tid,FormatVar('StdOutPipeSize=%d',buffsize));
 if task_run(tid)
 then LogResults(Now,cmd+LineEnding+FormatVar('PID %d Started.',task_pid(tid)))
 else LogResults(Now,cmd+LineEnding+'Run Failed.');
 myDimStatTids[tid]:=true;
 myDimStatStop[tid]:=0;
end;

procedure TMainForm.DimStatStop;
var tid:Integer;
begin
 for tid:=task_ref_min to task_ref_max do begin
  if (task_ref(tid)=nil) then continue;
  if myDimStatTids[tid] then begin
   if task_wait(tid,0) then begin
    task_kill(tid,1,0,DelayOnKill);
   end;
  end;
 end;
 DimStatKill;
end;

function TMainForm.dimStatExe(Mode:Integer=0):String;
var exe,path,padd,s:String; p,e:Integer;
begin
 if IsWindows then exe:='dimstat.exe' else exe:='dimStat';
 if (Mode&gt;0) then begin
  if IsUnix then begin
   path:=GetEnv('PATH')+PathSep+'/opt/dim';
   padd:=Trim(execute_command_as_text('unix printenv PATH',p,e));
   path:=path+PathSep+padd; s:=FileSearch(exe,path,false);
   if (s&lt;&gt;'') and FileExists(s) then exe:=s;
  end;
 end;
 Result:=exe;
end;

function TMainForm.GetHostName:String;
begin
 Result:='';
 if IsUnix then Result:=AnsiLowerCase(Trim(GetEnv('HOSTNAME'))) else
 if IsWindows then Result:=AnsiLowerCase(Trim(GetEnv('ComputerName')));
end;

procedure TMainForm.DimStatKill;
begin
 if (CRW_DAQ_SYS_EXE_PID=0) then begin
  if IsWindows
  then Exec('taskkill /f /im '+dimStatExe)
  else Exec('pkill '+dimStatExe);
 end else begin
  if IsWindows
  then PostCommandToCrwDaq('@run /sw7 taskkill /f /im '+dimStatExe)
  else PostCommandToCrwDaq('@run /sw0 pkill '+dimStatExe);
 end;
end;

var TheClsMarker:String='';
function ClsMarker:String;
var i:Integer;
begin
 if (TheClsMarker='') then for i:=1 to 10 do TheClsMarker:=TheClsMarker+LineEnding;
 Result:=TheClsMarker;
end;

procedure TMainForm.DimStatPoll;
var tid,n,p:Integer; lines:String; tstop:Double;
begin
 n:=0;
 for tid:=task_ref_min to task_ref_max do begin
  if (task_ref(tid)=nil) then continue;
  if myDimStatTids[tid] then begin
   if (task_rxcount(tid)&gt;0) then begin
    lines:=task_recv(tid,MaxInt);
    if (Length(lines)&gt;0) then begin
     p:=Pos(ClsMarker,lines);
     if (p&gt;0) then begin
      MemoMainResult.Clear; // Clear screen by CLS marker
      lines:=TrimLeft(Copy(lines,p+Length(ClsMarker),MaxInt));
     end;
     AddResults(Now,lines);
    end;
   end;
   if not task_wait(tid,0) then begin
    tstop:=myDimStatStop[tid];
    if (tstop=0) then begin
     myDimStatStop[tid]:=msecnow;
     tstop:=myDimStatStop[tid];
    end;
    if (msecnow-tstop&gt;DelayOnStop) then begin
     LogResults(Now,FormatVar('PID %d',task_pid(tid))
                   +FormatVar(' Stopped with exit code %d',task_result(tid)));
     myDimStatTids[tid]:=false;
     myDimStatStop[tid]:=0;
     task_free(tid);
    end;
   end;
   inc(n);
  end;
 end;
 if ((myTaskPollNum mod 10)=0) then begin
  n:=WordCount(GetListOfProcesses(0,0,dimStatExe),LineEnding);
  LabelDimStatRunStatus.Caption:=FormatVar(' %d '+dimStatExe+' instance(s) running ',n);
 end;
end;

function TMainForm.OPT_VERBOSE(Prefix:String=''):String;
begin
 Result:='';
 if CheckBoxDimStatOptVerbose.Enabled then
 if CheckBoxDimStatOptVerbose.Checked then Result:='--verbose';
 if (Prefix&lt;&gt;'') and (Result&lt;&gt;'') then Result:=Prefix+Result;
end;

function TMainForm.OPT_NOSTDERR(Prefix:String=''):String;
begin
 Result:='';
 if CheckBoxDimStatOptNostderr.Enabled then
 if CheckBoxDimStatOptNostderr.Checked then Result:='--nostderr';
 if (Prefix&lt;&gt;'') and (Result&lt;&gt;'') then Result:=Prefix+Result;
end;

function TMainForm.OPT_BUFFER_SIZE(Prefix:String=''):String;
begin
 Result:='';
 if CheckBoxDimStatOptBufferSize.Enabled then
 if CheckBoxDimStatOptBufferSize.Checked then Result:=Trim(ComboBoxDimStatParBufferSize.Text);
 if (Prefix&lt;&gt;'') and (Result&lt;&gt;'') then Result:=Prefix+Result;
end;

function TMainForm.OPT_TIMEOUT(Prefix:String=''):String;
begin
 Result:='';
 if CheckBoxDimStatOptTimeout.Enabled then
 if CheckBoxDimStatOptTimeout.Checked then Result:=Trim(ComboBoxDimStatParTimeout.Text);
 if (Prefix&lt;&gt;'') and (Result&lt;&gt;'') then Result:=Prefix+Result;
end;

function TMainForm.OPT_DNS(Prefix:String=''):String;
begin
 Result:=DIM_DNS_NODE;
 if CheckBoxDimStatOptDns.Enabled then
 if CheckBoxDimStatOptDns.Checked then Result:=Trim(ComboBoxDimStatParDns.Text);
 if (Prefix&lt;&gt;'') and (Result&lt;&gt;'') then Result:=Prefix+Result;
end;

function TMainForm.OPT_ACTION(Prefix:String=''):String;
begin
 Result:=Trim(ComboBoxDimStatAction.Text);
 if (Prefix&lt;&gt;'') and (Result&lt;&gt;'') then Result:=Prefix+Result;
end;

function TMainForm.OPT_TARGET(Prefix:String=''):String;
begin
 Result:='';
 if ComboBoxDimStatTarget.Enabled then Result:=Trim(ComboBoxDimStatTarget.Text);
 if (Prefix&lt;&gt;'') and (Result&lt;&gt;'') then Result:=Prefix+Result;
end;

function TMainForm.OPT_NOHEAD(Prefix:String=''):String;
begin
 Result:='';
 if CheckBoxDimStatOptNohead.Enabled then
 if CheckBoxDimStatOptNohead.Checked then Result:='--nohead';
 if (Prefix&lt;&gt;'') and (Result&lt;&gt;'') then Result:=Prefix+Result;
end;

function TMainForm.OPT_SORT(Prefix:String=''):String;
begin
 Result:='';
 if CheckBoxDimStatOptSort.Enabled then
 if CheckBoxDimStatOptSort.Checked then
 if ComboBoxDimStatOptSort.Enabled then Result:=Trim(ComboBoxDimStatOptSort.Text);
 if (Prefix&lt;&gt;'') and (Result&lt;&gt;'') then Result:=Prefix+Result;
end;

function TMainForm.OPT_STAT(Prefix:String=''):String;
begin
 Result:='';
 if CheckBoxDimStatOptStat.Enabled then
 if CheckBoxDimStatOptStat.Checked then Result:=Trim(ComboBoxDimStatParStat.Text);
 if (Prefix&lt;&gt;'') and (Result&lt;&gt;'') then Result:=Prefix+Result;
end;

function TMainForm.OPT_LOOP(Prefix:String=''):String;
begin
 Result:='';
 if CheckBoxDimStatOptLoop.Enabled then
 if CheckBoxDimStatOptLoop.Checked then Result:=Trim(ComboBoxDimStatParLoop.Text);
 if (Prefix&lt;&gt;'') and (Result&lt;&gt;'') then Result:=Prefix+Result;
end;

function TMainForm.OPT_TOP(Prefix:String=''):String;
begin
 Result:='';
 if CheckBoxDimStatOptTop.Enabled then
 if CheckBoxDimStatOptTop.Checked then Result:=Trim(ComboBoxDimStatParTop.Text);
 if (Prefix&lt;&gt;'') and (Result&lt;&gt;'') then Result:=Prefix+Result;
end;

function TMainForm.DefExecBuffKb:Integer;
begin
 Result:=StrToIntDef(Trim(ComboBoxDefExecBuffKb.Text),DivExecBuffKb);
 Result:=iMax(MinExecBuffKb,iMin(MaxExecBuffKb,Result));
end;

function TMainForm.BigExecBuffKb:Integer;
begin
 Result:=StrToIntDef(Trim(ComboBoxBigExecBuffKb.Text),BivExecBuffKb);
 Result:=iMax(MinExecBuffKb,iMin(MaxExecBuffKb,Result));
end;

function TMainForm.DefExecTimeOut:Integer;
begin
 Result:=StrToIntDef(Trim(ComboBoxDefExecTimeOut.Text),DivExecTimeout);
 Result:=iMax(MinExecTimeOut,iMin(MaxExecTimeOut,Result));
end;

function TMainForm.BigExecTimeOut:Integer;
begin
 Result:=StrToIntDef(Trim(ComboBoxBigExecTimeOut.Text),BivExecTimeout);
 Result:=iMax(MinExecTimeOut,iMin(MaxExecTimeOut,Result));
end;

function TMainForm.GetDimStatServers(aList:TStrings=nil):String;
var i,n:Integer; Lines,Items:TStringList; s:String;
begin
 Result:='';
 try
  Lines:=TStringList.Create;
  Items:=TStringList.Create;
  try
   Lines.Text:=Exec(dimStatExe(1)+OPT_DNS(' --dns ')+' --servers');
   if (aList&lt;&gt;nil) then Items.Text:=aList.Text;
   for i:=0 to Lines.Count-1 do
   if SameText(ExtractWord(1,Lines.Strings[i],' '+vbTab),'Server') then
   if TryStrToInt(ExtractWord(2,Lines.Strings[i],' '+vbTab),n) then begin
    s:=ExtractWord(3,Lines.Strings[i],' '+vbCrLf+vbTab);
    if (s&lt;&gt;'') and (Items.IndexOf(s)&lt;0) then Items.Add(s);
   end;
   Result:=Items.Text;
   if (aList&lt;&gt;nil) then aList.Text:=Items.Text;
  finally
   Lines.Free;
   Items.Free;
  end;
 except
  on E:Exception do Self.BugReport(E,Self,'GetDimStatServers');
 end;
end;

function TMainForm.GetDimStatServices(aList:TStrings=nil):String;
var i,n,nw:Integer; Lines,Items:TStringList; s,wc:String;
begin
 Result:='';
 try
  Lines:=TStringList.Create;
  Items:=TStringList.Create;
  try
   Lines.Text:=Exec(dimStatExe(1)+OPT_DNS(' --dns ')+' --services *',BigExecTimeOut,BigExecBuffKb);
   if (aList&lt;&gt;nil) then Items.Text:=aList.Text;
   for i:=0 to Lines.Count-1 do
   if SameText(ExtractWord(1,Lines.Strings[i],' '+vbTab),'Service') then
   if TryStrToInt(ExtractWord(2,Lines.Strings[i],' '+vbTab),n) then begin
    s:=ExtractWord(3,Lines.Strings[i],' '+vbCrLf+vbTab);
    //if (s&lt;&gt;'') and (Items.IndexOf(s)&lt;0) then Items.Add(s);
    nw:=WordCount(s,'/'); if (nw&lt;2) then continue;
    wc:=ExtractWord(1,s,'/');
    for i:=2 to nw do begin
     wc:=wc+'/*';
     if (Items.IndexOf(wc)&lt;0) then Items.Add(wc);
     wc:=Copy(wc,1,Length(wc)-1)+ExtractWord(i,s,'/');
    end;
   end;
   Result:=Items.Text;
   if (aList&lt;&gt;nil) then aList.Text:=Items.Text;
  finally
   Lines.Free;
   Items.Free;
  end;
 except
  on E:Exception do Self.BugReport(E,Self,'GetDimStatServices');
 end;
end;

procedure TMainForm.UpdateState(flags:Integer);
begin
 try
  // Updates on Initialization
  if HasFlags(flags,us_Init) then begin
   myDIM_DNS_NODE:=GetEnv('DIM_DNS_NODE');
   myComputerName:=GetHostName;
   ComboBoxDimStatParDns.Items.Clear;
   if not IsEmptyStr(DIM_DNS_NODE) then ComboBoxDimStatParDns.Items.Add(DIM_DNS_NODE);
   if not IsEmptyStr(ComputerName) then ComboBoxDimStatParDns.Items.Add(ComputerName);
   ComboBoxDimStatParDns.Items.Add('localhost');
   if IsEmptyStr(DIM_DNS_NODE)
   then ComboBoxDimStatParDns.Text:='localhost'
   else ComboBoxDimStatParDns.Text:=DIM_DNS_NODE;
  end;
  // Updates on Action change
  if HasFlags(flags,us_Action) then begin
   if SameText(ComboBoxDimStatAction.Text,'--serverservices') then begin
    CheckBoxDimStatOptStat.Enabled:=true;
    CheckBoxDimStatOptSort.Enabled:=true;
    ComboBoxDimStatTarget.Enabled:=true;
    ComboBoxDimStatTarget.Items.Clear;
    ComboBoxDimStatTarget.Items.Add('DIS_DNS');
    GetDimStatServers(ComboBoxDimStatTarget.Items);
    ComboBoxDimStatTarget.Text:='DIS_DNS';
   end else
   if SameText(ComboBoxDimStatAction.Text,'--serverclients') then begin
    CheckBoxDimStatOptStat.Enabled:=false;
    CheckBoxDimStatOptSort.Enabled:=true;
    ComboBoxDimStatTarget.Enabled:=true;
    ComboBoxDimStatTarget.Items.Clear;
    ComboBoxDimStatTarget.Items.Add('DIS_DNS');
    GetDimStatServers(ComboBoxDimStatTarget.Items);
    ComboBoxDimStatTarget.Text:='DIS_DNS';
   end else
   if SameText(ComboBoxDimStatAction.Text,'--services') then begin
    CheckBoxDimStatOptStat.Enabled:=true;
    CheckBoxDimStatOptSort.Enabled:=true;
    ComboBoxDimStatTarget.Enabled:=true;
    ComboBoxDimStatTarget.Items.Clear;
    ComboBoxDimStatTarget.Items.Add('*');
    ComboBoxDimStatTarget.Items.Add('DIS_DNS/*');
    GetDimStatServices(ComboBoxDimStatTarget.Items);
    ComboBoxDimStatTarget.Text:='*';
   end else
   if SameText(ComboBoxDimStatAction.Text,'--servers') then begin
    CheckBoxDimStatOptStat.Enabled:=false;
    CheckBoxDimStatOptSort.Enabled:=true;
    ComboBoxDimStatTarget.Enabled:=false;
    ComboBoxDimStatTarget.Items.Clear;
    ComboBoxDimStatTarget.Text:='';
   end else
   if SameText(ComboBoxDimStatAction.Text,'--running') then begin
    CheckBoxDimStatOptStat.Enabled:=false;
    CheckBoxDimStatOptSort.Enabled:=false;
    ComboBoxDimStatTarget.Enabled:=false;
    ComboBoxDimStatTarget.Items.Clear;
    ComboBoxDimStatTarget.Text:='';
   end else
   if SameText(ComboBoxDimStatAction.Text,'--version') then begin
    CheckBoxDimStatOptStat.Enabled:=false;
    CheckBoxDimStatOptSort.Enabled:=false;
    ComboBoxDimStatTarget.Enabled:=false;
    ComboBoxDimStatTarget.Items.Clear;
    ComboBoxDimStatTarget.Text:='';
   end else
   if SameText(ComboBoxDimStatAction.Text,'--help') then begin
    CheckBoxDimStatOptStat.Enabled:=false;
    CheckBoxDimStatOptSort.Enabled:=false;
    ComboBoxDimStatTarget.Enabled:=false;
    ComboBoxDimStatTarget.Items.Clear;
    ComboBoxDimStatTarget.Text:='';
   end;
   LabelDimStatOptTarget.Enabled:=ComboBoxDimStatTarget.Enabled;
  end;
  // Updates on Timer Poll
  if HasFlags(flags,us_Timer) then begin
   ComboBoxDimStatOptSort.Enabled:=CheckBoxDimStatOptSort.Enabled and CheckBoxDimStatOptSort.Checked;
   ComboBoxDimStatParStat.Enabled:=CheckBoxDimStatOptStat.Enabled and CheckBoxDimStatOptStat.Checked;
   CheckBoxDimStatOptLoop.Enabled:=CheckBoxDimStatOptStat.Enabled and CheckBoxDimStatOptStat.Checked;
   ComboBoxDimStatParLoop.Enabled:=CheckBoxDimStatOptLoop.Enabled and CheckBoxDimStatOptLoop.Checked;
   CheckBoxDimStatOptTop.Enabled:=CheckBoxDimStatOptStat.Enabled and CheckBoxDimStatOptStat.Checked;
   ComboBoxDimStatParTop.Enabled:=CheckBoxDimStatOptTop.Enabled and CheckBoxDimStatOptTop.Checked;
   ComboBoxDimStatParTimeout.Enabled:=CheckBoxDimStatOptTimeout.Enabled and CheckBoxDimStatOptTimeout.Checked;
   ComboBoxDimStatParBufferSize.Enabled:=CheckBoxDimStatOptBufferSize.Enabled and CheckBoxDimStatOptBufferSize.Checked;
   if CheckBoxDimStatOptDns.Checked then begin
    ComboBoxDimStatParDns.Enabled:=true;
    if not ComboBoxDimStatParDns.Focused then begin
     if (ComboBoxDimStatParDns.Text='') then ComboBoxDimStatParDns.Text:=DIM_DNS_NODE;
     if (ComboBoxDimStatParDns.Text='') then ComboBoxDimStatParDns.Text:='localhost';
    end;
   end else begin
    ComboBoxDimStatParDns.Enabled:=false;
    ComboBoxDimStatParDns.Text:=DIM_DNS_NODE;
   end;
   PanelDimStatCmdLine.Caption:='@run '+GetDimStatCmdLine;
  end;
 except
  on E:Exception do Self.BugReport(E,Self,'UpdateState');
 end;
end;

function TMainForm.GetDimStatCmdLine(NoCmd:Boolean=false):String;
var m:Integer;
begin
 if NoCmd then Result:='' else Result:=ComboBoxDimStatCmd.Text;
 if IsEmptyStr(Result) then m:=1 else m:=0;
 Result:=Trim(Result+' '+dimStatExe(m));
 Result:=Result+OPT_VERBOSE(' ');
 Result:=Result+OPT_NOSTDERR(' ');
 Result:=Result+OPT_BUFFER_SIZE(' --buffer-size ');
 Result:=Result+OPT_TIMEOUT(' --timeout ');
 Result:=Result+OPT_DNS(' --dns ');
 Result:=Result+OPT_SORT(' ');
 Result:=Result+OPT_NOHEAD(' ');
 Result:=Result+OPT_STAT(' --stat ');
 Result:=Result+OPT_LOOP(' --loop ');
 Result:=Result+OPT_TOP(' --top ');
 Result:=Result+OPT_ACTION(' ');
 Result:=Result+OPT_TARGET(' ');
end;

procedure TMainForm.TrayIconMainClick(Sender: TObject);
begin
 ActionMainFormShow.Execute;
end;

procedure TMainForm.TrayIconMainDblClick(Sender: TObject);
begin
 ActionMainFormShow.Execute;
end;

procedure TMainForm.TimerLogEventsUpdaterTimer(Sender: TObject);
begin
 try
  MoveBugReportListToLogger(nil);
  MoveLogEventsListToLoggerMemo(MemoLogEvents);
  if (PageControlMain.ActivePage=TabSheetLogEvents) then
  StatusBarLogEvents.SimpleText:=DateTimePrompt(Now)+GetHeapStatusBrief
   +FormatVar('. Events: %d',LogCountTotal)
   +FormatVar(', Bugs: %d',BugCountTotal)+'.';
  HandlePendingHideApplicationIconFromTaskBar;
 except
  on E:Exception do Self.BugReport(E,Self,'TimerLogEventsUpdaterTimer');
 end;
end;

procedure TMainForm.ActionMainExitExecute(Sender: TObject);
begin
 Application.Terminate;
end;

procedure TMainForm.ActionMainParentShowExecute(Sender: TObject);
begin
  AppActivateByTitle(ParentCrwDaqTitle);
end;

procedure TMainForm.ActionMainFormShowExecute(Sender: TObject);
begin
 ShowAndActivateFormByReference(Self,SW_SHOW);
end;

procedure TMainForm.ActionDimStatSendExecute(Sender: TObject);
begin
 try
  if (CRW_DAQ_SYS_EXE_PID=0)
  then RaiseException('Parent Crw32.exe process is not specified.');
  EditDimStatSend.Text:=Trim(EditDimStatSend.Text);
  if (Pos('@',EditDimStatSend.Text)&lt;&gt;1)
  then RaiseException('Invalid format of command.');
  if SameText(ExtractWord(1,EditDimStatSend.Text,' '),'@run')
  then PostCommandToCrwDaq(EditDimStatSend.Text)
  else SendCommandToCrwDaq(EditDimStatSend.Text);
 except
  on E:Exception do Self.BugReport(E,Self,'ActionDimStatSendExecute');
 end;
end;

procedure TMainForm.ActionDimStatRunExecute(Sender: TObject);
begin
 try
  DimStatRun;
 except
  on E:Exception do Self.BugReport(E,Self,'ActionDimStatRunExecute');
 end;
end;

procedure TMainForm.ActionDimStatStopExecute(Sender: TObject);
begin
 try
  if(GetListOfProcesses(0,0,dimStatExe)='') then begin
   LogResults(Now,'Not found '+dimStatExe+' instances running.');
   Exit;
  end;
  DimStatStop;
 except
  on E:Exception do Self.BugReport(E,Self,'ActionDimStatStopExecute');
 end;
end;

procedure TMainForm.ActionMainLogEventsClearExecute(Sender: TObject);
begin
 MemoLogEvents.Lines.Clear;
 LogCountTotal:=0; BugCountTotal:=0;
 LogEvents(Now,GetBriefEngineScriptInfo);
 LogEvents(Now,'Start.');
end;

procedure TMainForm.ActionMainLogEventsGoBackExecute(Sender: TObject);
begin
 PageControlMain.ActivePage:=TabSheetMain;
end;

procedure TMainForm.ActionMainListSysInfoExecute(Sender: TObject);
var What,Info:String; Timeout:Integer;
begin
 Timeout:=1000*SpinEditMainListSysInfoTimeOut.Value;
 What:=Trim(ComboBoxMainListSysInfo.Text);
 Info:=ListSysInfoAsText(What,Timeout);
 LogEvents(Now,What);
 LogEvents(0,Info);
end;

var BugTestNum:Integer=0;

procedure TMainForm.BitBtnLogEventsTestClick(Sender: TObject);
begin
 try
  Inc(BugTestNum);
  RaiseException('This is exception test '+IntToStr(BugTestNum));
 except
  on E:Exception do Self.BugReport(E,Self,'BitBtnLogEventsTestClick');
 end;
end;

procedure TMainForm.ActionMainResultFontDecExecute(Sender: TObject);
begin
 try
  if (MemoMainResult.Font.Size&gt;MinFontSize)
  then MemoMainResult.Font.Size:=MemoMainResult.Font.Size-1;
 except
  on E:Exception do Self.BugReport(E,Self,'ActionMainResultFontDecExecute');
 end;
end;

procedure TMainForm.ActionMainResultFontIncExecute(Sender: TObject);
begin
 try
  if (MemoMainResult.Font.Size&lt;MaxFontSize)
  then MemoMainResult.Font.Size:=MemoMainResult.Font.Size+1;
 except
  on E:Exception do Self.BugReport(E,Self,'ActionMainResutFontIncExecute');
 end;
end;

procedure TMainForm.ActionMainResultFontDefExecute(Sender: TObject);
begin
 try
  MemoMainResult.Font.Size:=DefFontSize;
 except
  on E:Exception do Self.BugReport(E,Self,'ActionMainResultFontDefExecute');
 end;
end;

procedure TMainForm.ImageDimLogoClick(Sender: TObject);
begin
 Exec('firefox http://dim.web.cern.ch');
end;

procedure TMainForm.ImageCernLogoClick(Sender: TObject);
begin
 Exec('firefox http://cern.ch');
end;

procedure TMainForm.TimerDimStatUpdaterTimer(Sender: TObject);
var us_addon:Integer;
begin
 us_addon:=0;
 if not SameText(myLastAction,ComboBoxDimStatAction.Text) then begin
  myLastAction:=ComboBoxDimStatAction.Text;
  us_addon:=us_Action;
 end;
 if (myLastOptStat&lt;&gt;Ord(CheckBoxDimStatOptStat.Checked)) then begin
  myLastOptStat:=Ord(CheckBoxDimStatOptStat.Checked);
  us_addon:=us_Action;
 end;
 UpdateState(us_Timer+us_addon);
end;

procedure TMainForm.ActionDimStatCopyCmdLineExecute(Sender: TObject);
begin
 EditDimStatSend.Text:='@run '+GetDimStatCmdLine;
 Success('Copy command: '+EditDimStatSend.Text);
end;

procedure TMainForm.ActionMainResultSelectAllExecute(Sender: TObject);
begin
 try
  MemoMainResult.SelectAll;
 except
  on E:Exception do Self.BugReport(E,Self,'ActionMainResultSelectAllExecute');
 end;
end;

procedure TMainForm.ActionMainResultSelectNoneExecute(Sender: TObject);
begin
 try
  MemoMainResult.SelLength:=0;
 except
  on E:Exception do Self.BugReport(E,Self,'ActionMainResultSelectNoneExecute');
 end;
end;

procedure TMainForm.ActionMainResultCutExecute(Sender: TObject);
begin
 try
  ActionMainResultCopy.Execute;
  ActionMainResultClear.Execute;
 except
  on E:Exception do Self.BugReport(E,Self,'ActionMainResultCutExecute');
 end;
end;

procedure TMainForm.ActionMainResultClearExecute(Sender: TObject);
begin
 try
  if (MemoMainResult.SelLength&lt;1) then MemoMainResult.Clear;
  if (MemoMainResult.SelLength&gt;0) then MemoMainResult.ClearSelection;
  Success('Clear Result.');
 except
  on E:Exception do Self.BugReport(E,Self,'ActionMainResultClearExecute');
 end;
end;

procedure TMainForm.ActionMainResultCopyExecute(Sender: TObject);
begin
 try
  if (MemoMainResult.SelLength&lt;1) then Clipboard.AsText:=MemoMainResult.Lines.Text;
  if (MemoMainResult.SelLength&gt;0) then Clipboard.AsText:=MemoMainResult.SelText;
  Success('Copy Result to Clipboard.');
 except
  on E:Exception do Self.BugReport(E,Self,'ActionMainResultCopyExecute');
 end;
end;

procedure TMainForm.TimerTaskPollTimer(Sender: TObject);
begin
 try
  DimStatPoll;
  inc(myTaskPollNum);
 except
  on E:Exception do Self.BugReport(E,Self,'TimerTaskPollTimer');
 end;
end;

end.
</Code>
        </Main>
      </Child>
    </dimStatGui>
  </Metadata>
</CrossEngineApp>
