Browse Source

* overloaded version of raiselastoserror that allows custom errorcodes
to be raised, patch by Cytax, Mantis #21092

git-svn-id: trunk@20084 -

marco 13 years ago
parent
commit
1f40ff2362
2 changed files with 18 additions and 10 deletions
  1. 2 1
      rtl/objpas/sysutils/osutilsh.inc
  2. 16 9
      rtl/objpas/sysutils/sysutils.inc

+ 2 - 1
rtl/objpas/sysutils/osutilsh.inc

@@ -19,7 +19,8 @@ Type TExecuteFlags = Set of ( ExecInheritsHandles);
 {$ifdef HAS_OSERROR}
 {$ifdef HAS_OSERROR}
 Function GetLastOSError : Integer;
 Function GetLastOSError : Integer;
 {$endif}
 {$endif}
-Procedure RaiseLastOSError;
+Procedure RaiseLastOSError;overload;
+Procedure RaiseLastOSError(LastError: Integer);overload;
 Function GetEnvironmentVariable(Const EnvVar : String) : String;
 Function GetEnvironmentVariable(Const EnvVar : String) : String;
 Function GetEnvironmentVariableCount : Integer;
 Function GetEnvironmentVariableCount : Integer;
 Function GetEnvironmentString(Index : Integer) : String;
 Function GetEnvironmentString(Index : Integer) : String;

+ 16 - 9
rtl/objpas/sysutils/sysutils.inc

@@ -408,27 +408,34 @@ begin
 end;
 end;
 
 
 {$IFDEF HAS_OSERROR}
 {$IFDEF HAS_OSERROR}
-Procedure RaiseLastOSError;
+Procedure RaiseLastOSError;overload;
+begin
+  RaiseLastOSError(GetLastOSError);
+end;
 
 
+Procedure RaiseLastOSError(LastError: Integer);overload;
 var
 var
-  ECode: Cardinal;
   E : EOSError;
   E : EOSError;
-
 begin
 begin
-  ECode := GetLastOSError;
-  If (ECode<>0) then
-    E:=EOSError.CreateFmt(SOSError, [ECode, SysErrorMessage(ECode)])
+  If (LastError<>0) then
+    E:=EOSError.CreateFmt(SOSError, [LastError, SysErrorMessage(LastError)])
   else
   else
     E:=EOSError.Create(SUnkOSError);
     E:=EOSError.Create(SUnkOSError);
-  E.ErrorCode:=ECode;
+  E.ErrorCode:=LastError;
   Raise E;
   Raise E;
 end;
 end;
-{$else}
-Procedure RaiseLastOSError;
 
 
+{$else}
+Procedure RaiseLastOSError;overload;
 begin
 begin
   Raise Exception.Create('RaiseLastOSError not implemented on this platform.');
   Raise Exception.Create('RaiseLastOSError not implemented on this platform.');
 end;
 end;
+
+Procedure RaiseLastOSError(LastError: Integer);overload;
+begin
+  RaiseLastOSError;
+end;
+
 {$endif}
 {$endif}
 Procedure AssertErrorHandler (Const Msg,FN : ShortString;LineNo:longint; TheAddr : pointer);
 Procedure AssertErrorHandler (Const Msg,FN : ShortString;LineNo:longint; TheAddr : pointer);
 Var
 Var