Browse Source

* Introduce ToString for all enumerateds.

Michaël Van Canneyt 1 year ago
parent
commit
d56da2d930
2 changed files with 79 additions and 3 deletions
  1. 28 2
      packages/fcl-process/src/process.pp
  2. 51 1
      packages/fcl-process/src/processbody.inc

+ 28 - 2
packages/fcl-process/src/process.pp

@@ -10,11 +10,13 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
  **********************************************************************}
-{$mode objfpc}
-{$h+}
 {$IFNDEF FPC_DOTTEDUNITS}
 unit process;
 {$ENDIF FPC_DOTTEDUNITS}
+{$define windows}
+{$mode objfpc}
+{$h+}
+{$modeswitch typehelpers}
 
 interface
 
@@ -37,21 +39,38 @@ Type
                     poDefaultErrorMode,poNewProcessGroup,
                     poDebugProcess,poDebugOnlyThisProcess,poDetached,
                     poPassInput,poRunIdle);
+  TProcessOptionHelper = type helper for TProcessOption
+    function ToString : String;
+  end;
 
   TShowWindowOptions = (swoNone,swoHIDE,swoMaximize,swoMinimize,swoRestore,swoShow,
                         swoShowDefault,swoShowMaximized,swoShowMinimized,
                         swoshowMinNOActive,swoShowNA,swoShowNoActivate,swoShowNormal);
+  TShowWindowOptionsHelper = type helper for TShowWindowOptions
+    function ToString : String;
+  end;
 
   TStartupOption = (suoUseShowWindow,suoUseSize,suoUsePosition,
                     suoUseCountChars,suoUseFillAttribute);
+  TStartupOptionHelper = type helper for TStartupOption
+    function ToString : String;
+  end;
 
   // only win32/64 and wince uses this. wince doesn't have the constants in the headers for the latter two.
   // unix defines them (as nice levels?), but doesn't use them.
   TProcessPriority = (ppHigh,ppIdle,ppNormal,ppRealTime{$ifndef wince},ppBelowNormal,ppAboveNormal{$endif});
+  TProcessPriorityhelper = type helper for TProcessPriority
+    function ToString : String;
+  end;
 
   TProcessOptions = set of TProcessOption;
   TStartupOptions = set of TStartupOption;
+
   TRunCommandEventCode = (RunCommandIdle,RunCommandReadOutputString,RunCommandReadOutputStream,RunCommandFinished,RunCommandException);
+  TRunCommandEventCodeHelper = type helper for TRunCommandEventCode
+    function ToString : string;
+  end;
+
   TRunCommandEventCodeSet = set of TRunCommandEventCode;
   TOnRunCommandEvent = procedure(Sender,Context : TObject;Status:TRunCommandEventCode;const Message:string) of object;
   EProcess = Class(Exception);
@@ -61,7 +80,14 @@ Type
   {$endif UNIX}
 
   TIOType = (iotDefault, iotPipe, iotFile, iotHandle, iotProcess, iotNull);
+  TIOTypeHelper = type helper for TIOType
+    function ToString : string;
+  end;
+
   TProcessHandleType = (phtInput,phtOutput,phtError);
+  TProcessHandleTypeHelper = type helper for TProcessHandleType
+    function ToString : string;
+  end;
 
   TGetHandleEvent = procedure(Sender : TObject; var aHandle : THandle; var CloseOnExecute : Boolean) of object;
   TAfterAllocateHandleEvent = procedure(Sender : TObject; aHandle : THandle; var CloseOnExecute : Boolean) of object;

+ 51 - 1
packages/fcl-process/src/processbody.inc

@@ -1,3 +1,4 @@
+{%MainUnit process.pp}
 {
     This file is part of the Free Component Library (FCL)
     Copyright (c) 1999-2000 by the Free Pascal development team
@@ -269,6 +270,55 @@ implementation
 
 {$i process.inc}
 
+function TIOTypeHelper.ToString : string;
+
+begin
+  WriteStr(Result,Self);
+end;
+
+{ TProcessHandleTypeHelper }
+
+function TProcessHandleTypeHelper.ToString: string;
+begin
+  WriteStr(Result,Self);
+end;
+
+
+{ TProcessOption }
+
+function TProcessOptionHelper.ToString: String;
+begin
+  WriteStr(Result,Self);
+end;
+
+{ TShowWindowOptionsHelper }
+
+function TShowWindowOptionsHelper.ToString: String;
+begin
+  WriteStr(Result,Self);
+end;
+
+{ TStartupOptionHelper }
+
+function TStartupOptionHelper.ToString: String;
+begin
+  WriteStr(Result,Self);
+end;
+
+{ TProcessPriorityhelper }
+
+function TProcessPriorityhelper.ToString: String;
+begin
+  WriteStr(Result,Self);
+end;
+
+{ TRunCommandEventCodeHelper }
+
+function TRunCommandEventCodeHelper.ToString: string;
+begin
+  WriteStr(Result,Self);
+end;
+
 
 
 Procedure CommandToList(S : TProcessString; List : TProcessStrings);
@@ -1083,7 +1133,7 @@ begin
   If (FTheirHandleIOType=iotDefault) or not (CloseHandleOnExecute or aForceClose) then
     begin
     FTheirHandle:=THandle(INVALID_HANDLE_VALUE);
-     exit;
+    exit;
     end;
   H:=ResolveProcessHandle;
   // Writeln(StdErr,GetProcessID,' : ',ProcessHandleType,' closing their handle ',IOType,': ',H);