<?xml version="1.0" encoding="utf-8"?>
<CrossEngineApp Version="1">
  <Options>object ProjOption: TProjectOptions
  Title = 'DemoPing'
  AppName = 'DemoPing'
  Language = 'PASCAL'
  AppIcon.Data = {
[encoded data, 9246 characters]
    FCFF
  }
  AppAutor = 'Copyright(c) 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'
    'dpGuiResTools'
  )
end
</Options>
  <Metadata>
    <DemoPing ImageIndex="2">
      <Object ClassName=""/>
      <Code>program DemoPing;

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

begin
  InitGuiResMain; // Init GUI Resources - Main
  SetCrwDaqChildTitle('Demo Ping Example');
  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 = 307
  Height = 350
  Top = 124
  Width = 660
  BorderWidth = 4
  Caption = 'MainForm'
  ClientHeight = 350
  ClientWidth = 660
  Constraints.MinHeight = 350
  Constraints.MinWidth = 660
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  ParentFont = True
  ShowHint = True
  LCLVersion = '2.2.6.0'
  object PanelMain: TPanel
    Left = 4
    Height = 342
    Top = 4
    Width = 652
    Align = alClient
    BorderWidth = 4
    ClientHeight = 342
    ClientWidth = 652
    TabOrder = 0
    object PageControlMain: TPageControl
      Left = 5
      Height = 332
      Top = 5
      Width = 642
      ActivePage = TabSheetMain
      Align = alClient
      Images = DataModuleGuiResMain.ImageListMain32x32
      TabIndex = 0
      TabOrder = 0
      object TabSheetMain: TTabSheet
        Caption = 'Main  '
        ClientHeight = 288
        ClientWidth = 632
        ImageIndex = 114
        object PanelMainContent: TPanel
          Left = 0
          Height = 170
          Top = 0
          Width = 632
          Align = alClient
          BorderWidth = 8
          ClientHeight = 170
          ClientWidth = 632
          TabOrder = 0
          object LabelMainExecUserCmnd: TLabel
            Left = 9
            Height = 15
            Top = 9
            Width = 614
            Align = alTop
            Caption = 'Result:'
            ParentColor = False
          end
          object MemoMainExecUserCmnd: TMemo
            Left = 9
            Height = 137
            Top = 24
            Width = 614
            Align = alClient
            Color = clInfoBk
            ReadOnly = True
            ScrollBars = ssAutoBoth
            TabOrder = 0
            WordWrap = False
          end
        end
        object PanelMainButtons: TPanel
          Left = 0
          Height = 118
          Top = 170
          Width = 632
          Align = alBottom
          BorderWidth = 8
          ClientHeight = 118
          ClientWidth = 632
          TabOrder = 1
          object LabeUserCmnd: TLabel
            Left = 104
            Height = 15
            Top = 63
            Width = 160
            Caption = 'User command to run:'
            ParentColor = False
          end
          object BitBtnMainSendUserCmnd: TBitBtn
            Left = 8
            Height = 46
            Top = 60
            Width = 91
            Action = ActionMainRunUserCmnd
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 114
            TabOrder = 5
          end
          object BitBtnPingerStart: TBitBtn
            Left = 8
            Height = 46
            Hint = 'Run PING command for given Host Name.'
            Top = 8
            Width = 91
            Caption = 'Ping'
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 114
            OnClick = BitBtnPingerStartClick
            TabOrder = 0
          end
          object BitBtnMainProgramExit: TBitBtn
            Left = 532
            Height = 46
            Top = 60
            Width = 91
            Action = ActionMainProgramExit
            Anchors = [akTop, akRight]
            ModalResult = 11
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 113
            TabOrder = 7
          end
          object BitBtnMainParentShow: TBitBtn
            Left = 532
            Height = 46
            Top = 8
            Width = 91
            Action = ActionMainParentShow
            Anchors = [akTop, akRight]
            ModalResult = 11
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 234
            TabOrder = 4
          end
          object BitBtnPingerStop: TBitBtn
            Left = 436
            Height = 46
            Hint = 'Stop PING command.'
            Top = 8
            Width = 91
            Anchors = [akTop, akRight]
            Caption = 'Stop'
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 115
            OnClick = BitBtnPingerStopClick
            TabOrder = 3
          end
          object LabelPingerHost: TLabel
            Left = 192
            Height = 15
            Top = 8
            Width = 72
            Caption = 'Host Name'
            ParentColor = False
          end
          object ComboBoxPingerHost: TComboBox
            Left = 188
            Height = 27
            Top = 24
            Width = 246
            Anchors = [akTop, akLeft, akRight]
            DropDownCount = 24
            ItemHeight = 0
            ItemIndex = 0
            Items.Strings = (
              'localhost'
              '127.0.0.1'
            )
            TabOrder = 2
            Text = 'localhost'
          end
          object LabelPingerState: TLabel
            Left = 348
            Height = 15
            Top = 8
            Width = 80
            Anchors = [akTop, akRight]
            Caption = 'State: Off'
            ParentColor = False
          end
          object ComboBoxPingerOpt: TComboBox
            Left = 104
            Height = 27
            Top = 24
            Width = 84
            DropDownCount = 24
            ItemHeight = 0
            ItemIndex = 0
            Items.Strings = (
              ''
              '-t'
              '-n 4'
              '-c 4'
            )
            TabOrder = 1
          end
          object LabelPingerOpt: TLabel
            Left = 104
            Height = 15
            Top = 8
            Width = 72
            Caption = 'Option(s)'
            ParentColor = False
          end
          object ComboBoxMainRunUserCmnd: TComboBox
            Left = 104
            Height = 27
            Top = 76
            Width = 424
            Anchors = [akTop, akLeft, akRight]
            DropDownCount = 24
            ItemHeight = 0
            Items.Strings = (
              'ping -t localhost'
              'xterm -e ping localhost'
              'fly-term -e ping localhost'
              'cmd'
              'xterm'
              'fly-term'
            )
            TabOrder = 6
            Text = 'xterm -e ping localhost'
          end
        end
      end
      object TabSheetLogEvents: TTabSheet
        BorderWidth = 8
        Caption = 'Log  '
        ClientHeight = 288
        ClientWidth = 632
        ImageIndex = 168
        object PanelLogEventsContent: TPanel
          Left = 0
          Height = 226
          Top = 0
          Width = 632
          Align = alClient
          BorderWidth = 8
          ClientHeight = 226
          ClientWidth = 632
          TabOrder = 0
          object LabelLogEvents: TLabel
            Left = 9
            Height = 15
            Top = 9
            Width = 614
            Align = alTop
            Caption = 'Event log (list of events occurred):'
            ParentColor = False
          end
          object MemoLogEvents: TMemo
            Left = 9
            Height = 176
            Top = 24
            Width = 614
            Align = alClient
            Color = clInfoBk
            ReadOnly = True
            ScrollBars = ssAutoBoth
            TabOrder = 0
            WordWrap = False
          end
          object StatusBarLogEvents: TStatusBar
            Left = 9
            Height = 17
            Top = 200
            Width = 614
            Panels = &lt;&gt;
          end
        end
        object PanelLogEventsButtons: TPanel
          Left = 0
          Height = 62
          Top = 226
          Width = 632
          Align = alBottom
          Anchors = [akRight, akBottom]
          BorderWidth = 8
          ClientHeight = 62
          ClientWidth = 632
          TabOrder = 1
          object BitBtnLogEventsTest: TBitBtn
            Left = 341
            Height = 46
            Hint = 'Raise exception for test.'
            Top = 8
            Width = 91
            Anchors = [akTop, akRight]
            Caption = ' Test'
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 115
            OnClick = BitBtnLogEventsTestClick
            TabOrder = 3
          end
          object BitBtnLogEventsClear: TBitBtn
            Left = 437
            Height = 46
            Top = 8
            Width = 91
            Action = ActionMainLogEventsClear
            Anchors = [akTop, akRight]
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 119
            TabOrder = 4
          end
          object BitBtnLogEventsGoBack: TBitBtn
            Left = 533
            Height = 46
            Top = 8
            Width = 91
            Action = ActionMainLogEventsGoBack
            Anchors = [akTop, akRight]
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 59
            TabOrder = 5
          end
          object BitBtnMainListSysInfo: TBitBtn
            Left = 244
            Height = 46
            Top = 8
            Width = 91
            Action = ActionMainListSysInfo
            Images = DataModuleGuiResMain.ImageListMain32x32
            ImageIndex = 124
            TabOrder = 2
          end
          object ComboBoxMainListSysInfo: TComboBox
            Left = 8
            Height = 27
            Top = 24
            Width = 180
            DropDownCount = 24
            ItemHeight = 0
            Items.Strings = (
              'list environ'
              'list session'
              'list modules 0'
              'list process 0 0 *'
              'list windows 0 * *'
            )
            TabOrder = 0
            Text = 'list environ'
          end
          object LabelMainListSysInfo: TLabel
            Left = 8
            Height = 15
            Top = 8
            Width = 88
            Caption = 'Info topic:'
            ParentColor = False
          end
          object SpinEditMainListSysInfoTimeOut: TSpinEdit
            Left = 188
            Height = 25
            Hint = 'Timeout for execution, sec.'
            Top = 24
            Width = 54
            MaxValue = 60
            MinValue = 1
            TabOrder = 1
            Value = 5
          end
          object LabelMainListSysInfoTimeOut: TLabel
            Left = 188
            Height = 15
            Top = 8
            Width = 56
            Caption = 'TimeOut'
            ParentColor = False
          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 ActionMainRunUserCmnd: TAction
      Caption = 'Run'
      Hint = 'Run user command.'
      ImageIndex = 64
      OnExecute = ActionMainRunUserCmndExecute
    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 ActionMainListSysInfo: TAction
      Caption = 'Info'
      Hint = 'Print system information by specified topic.'
      ImageIndex = 124
      OnExecute = ActionMainListSysInfoExecute
    end
  end
  object TrayIconMain: TTrayIcon
    PopUpMenu = PopupMenuTray
    Icon.Data = {
[encoded data, 9514 characters]
      FCFF
    }
    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 TimerPingerPoll: TTimer
    Interval = 50
    OnTimer = TimerPingerPollTimer
    Left = 284
  end
end
</Object>
          <Code>unit Main;

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

type
  TMainForm = class(TForm)
    TimerLogEventsUpdater: TTimer;
    ActionListMain: TActionList;
    ActionMainProgramExit: TAction;
    ActionMainParentShow: TAction;
    ActionMainFormShow: TAction;
    ActionMainRunUserCmnd: 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;
    LabelMainExecUserCmnd: TLabel;
    PanelMainButtons: TPanel;
    LabeUserCmnd: TLabel;
    BitBtnMainSendUserCmnd: TBitBtn;
    BitBtnPingerStart: 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;
    MemoMainExecUserCmnd: TMemo;
    TimerPingerPoll: TTimer;
    BitBtnPingerStop: TBitBtn;
    LabelPingerHost: TLabel;
    ComboBoxPingerHost: TComboBox;
    LabelPingerState: TLabel;
    ComboBoxPingerOpt: TComboBox;
    LabelPingerOpt: TLabel;
    ComboBoxMainRunUserCmnd: TComboBox;
    ActionMainListSysInfo: TAction;
    BitBtnMainListSysInfo: TBitBtn;
    ComboBoxMainListSysInfo: TComboBox;
    LabelMainListSysInfo: TLabel;
    SpinEditMainListSysInfoTimeOut: TSpinEdit;
    LabelMainListSysInfoTimeOut: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure TrayIconMainClick(Sender: TObject);
    procedure TrayIconMainDblClick(Sender: TObject);
    procedure TimerLogEventsUpdaterTimer(Sender: TObject);
    procedure ActionMainExitExecute(Sender: TObject);
    procedure ActionMainParentShowExecute(Sender: TObject);
    procedure ActionMainFormShowExecute(Sender: TObject);
    procedure ActionMainRunUserCmndExecute(Sender: TObject);
    procedure ActionMainLogEventsClearExecute(Sender: TObject);
    procedure ActionMainLogEventsGoBackExecute(Sender: TObject);
    procedure ActionMainListSysInfoExecute(Sender: TObject);
    procedure BitBtnLogEventsTestClick(Sender: TObject);
    procedure TimerPingerPollTimer(Sender: TObject);
    procedure BitBtnPingerStopClick(Sender: TObject);
    procedure BitBtnPingerStartClick(Sender: TObject);
  private
  protected
    pinger   : Integer;
  public
    procedure ShowTrayIcon;
    procedure AdjustComponents;
    procedure BugReport(E:Exception; Sender:TObject; Where:String);
    procedure SendCommandToCrwDaq(S:String; Activate:Boolean=true);
    procedure PostCommandToCrwDaq(S:String);
    function  PingerState:String;
    procedure PingerStart;
    procedure PingerStop;
    procedure PingerPoll;
  end;

var MainForm: TMainForm;

implementation

procedure TMainForm.FormCreate(Sender: TObject);
begin
 try
  defIpcInit;
  defParamsInit;
  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;
   //RaiseException('Parent CrwDaq process is not specified.');
  end;
 except
  on E:Exception do Self.BugReport(E,Self,'FormCreate');
 end;
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin
 PingerStop;
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;
begin
 ComboBoxMainListSysInfo.Items.Text:=GetItemsOfListSysInfoAsText;
 ComboBoxMainListSysInfo.ItemIndex:=0;
 MemoLogEvents.Font.Size:=10;
 LabelPingerOpt.Font.Size:=10;
 LabelPingerHost.Font.Size:=10;
 SetDefaultSansFontName(LabelPingerOpt.Font);
 SetDefaultSansFontName(LabelPingerHost.Font);
 LabelPingerState.Font.Style:=LabelPingerState.Font.Style+[fsBold];
 if IsWindows
 then ComboBoxMainRunUserCmnd.ItemIndex:=0
 else ComboBoxMainRunUserCmnd.ItemIndex:=1;
 if IsWindows
 then ComboBoxPingerOpt.ItemIndex:=1
 else ComboBoxPingerOpt.ItemIndex:=0;
 ComboBoxPingerHost.Items.Add(GetHostName);
 SetDefaultSansFontName(LabelMainListSysInfoTimeOut.Font);
 if IsWindows then ComboBoxMainRunUserCmnd.Text:='ping -t localhost';
 if IsUnix then ComboBoxMainRunUserCmnd.Text:='xterm -hold -e "ping localhost"';
 if IsWindows then ComboBoxPingerOpt.Text:='-t';
 if IsUnix then ComboBoxPingerOpt.Text:='';
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 CrwDaq 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);
 except
  on E:Exception do Self.BugReport(E,Self,'SendCommandToCrwDaq');
 end;
end;

procedure TMainForm.PostCommandToCrwDaq(S:String);
begin
 SendCommandToCrwDaq(S,false);
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
 PingerStop;
 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.ActionMainRunUserCmndExecute(Sender: TObject);
var cmd:String; tid:Integer;
begin
 try
  cmd:=Trim(ComboBoxMainRunUserCmnd.Text); if (cmd='') then Exit;
  tid:=task_init(cmd);
  if (tid&lt;&gt;0) then
  try
   if task_run(tid) then begin
    MemoMainExecUserCmnd.Lines.Add(FormatVar('Run tid %d',tid)
                                  +FormatVar(' pid %u',task_pid(tid))
                                  +FormatVar(' cmd "%s"',cmd));
   end else begin
    MemoMainExecUserCmnd.Lines.Add('Could not run: '+cmd);
   end;
  finally
   task_free(tid);
  end;
 except
  on E:Exception do Self.BugReport(E,Self,'ActionMainRunUserCmndExecute');
 end;
end;

function TMainForm.PingerState:String;
begin
 if (pinger=0) then Result:='OFF' else
 if not task_wait(pinger,0) then Result:='DEAD' else
 Result:=FormatVar('PID %d',task_pid(pinger));
end;

procedure TMainForm.PingerStart;
var arg:String;
begin
 try
  PingerStop;
  arg:=Trim(ComboBoxPingerHost.Text);
  arg:=Trim(ComboBoxPingerOpt.Text)+' '+arg;
  pinger:=task_init('ping '+arg);
  task_ctrl(pinger,'Display=SW_HIDE');
  task_ctrl(pinger,'HomeDir='+GetTempDir);
  task_ctrl(pinger,'StdInPipeSize='+IntToStr(1024*64));
  task_ctrl(pinger,'StdOutPipeSize='+IntToStr(1024*64));
  task_ctrl(pinger,'ProcessPriority='+IntToStr(8));
  if Windows then task_ctrl(pinger,'CodePage='+IntToStr(WinApi.GetOEMCP));
  if task_run(pinger) then begin
   MemoMainExecUserCmnd.Lines.Add('Run command:');
   MemoMainExecUserCmnd.Lines.Add(FormatVar('task_pid = %d',task_pid(pinger)));
   MemoMainExecUserCmnd.Lines.Add(FormatVar('task_appname = %s',task_ctrl(pinger,'AppName')));
   MemoMainExecUserCmnd.Lines.Add(FormatVar('task_cmdline = %s',task_ctrl(pinger,'CmdLine')));
   MemoMainExecUserCmnd.Lines.Add(FormatVar('task_exename = %s',task_ctrl(pinger,'ExeName')));
   MemoMainExecUserCmnd.Lines.Add(FormatVar('task_homedir = %s',task_ctrl(pinger,'HomeDir')));
   MemoMainExecUserCmnd.Lines.Add(FormatVar('task_display = %s',task_ctrl(pinger,'Display')));
   MemoMainExecUserCmnd.Lines.Add(FormatVar('task_stdinpipesize = %s',task_ctrl(pinger,'StdInPipeSize')));
   MemoMainExecUserCmnd.Lines.Add(FormatVar('task_priority = %s',task_ctrl(pinger,'ProcessPriority')));
   MemoMainExecUserCmnd.Lines.Add(FormatVar('task_codepage = %s',task_ctrl(pinger,'CodePage')));
  end else MemoMainExecUserCmnd.Lines.Add('Could not run command.');
 except
  on E:Exception do BugReport(E,Self,'PingerStart');
 end;
end;

procedure TMainForm.PingerStop;
var pid,cod:Integer;
begin
 try
  if (pinger&gt;0) then begin
   task_kill(pinger,1,0,1000); pid:=task_pid(pinger); cod:=task_result(pinger);
   MemoMainExecUserCmnd.Lines.Add(FormatVar('Process %u',pid)+FormatVar(' stopped with exit code %d',cod));
   task_free(pinger);
   pinger:=0;
  end;
 except
  on E:Exception do BugReport(E,Self,'PingerStop');
 end;
end;

procedure TMainForm.PingerPoll;
var data:String;
begin
 try
  if (pinger&gt;0) then
  if (task_rxcount(pinger)&gt;0) then begin
   data:=task_recv(pinger,MaxInt);
   if (Length(data)&gt;0) then begin
    StringsAppendFromText(MemoMainExecUserCmnd.Lines,data);
    MemoMainExecUserCmnd.SelStart:=MaxInt; // Scroll to End.
   end;
  end;
  LabelPingerState.Caption:='State: '+PingerState;
 except
  on E:Exception do BugReport(E,Self,'PingerPoll');
 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;

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.TimerPingerPollTimer(Sender: TObject);
begin
  PingerPoll;
end;

procedure TMainForm.BitBtnPingerStopClick(Sender: TObject);
begin
 PingerStop;
end;

procedure TMainForm.BitBtnPingerStartClick(Sender: TObject);
begin
 PingerStart;
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;

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