Browse Source

* Implement ListIndexError

Michaël Van Canneyt 1 year ago
parent
commit
8fb39925eb

+ 1 - 5
rtl/objpas/classes/classesh.inc

@@ -143,11 +143,7 @@ type
   EMethodNotFound = class(EFilerError);
   EInvalidImage = class(EFilerError);
   EResNotFound = class(Exception);
-{$ifdef FPC_TESTGENERICS}
-  EListError = fgl.EListError;
-{$else}
-  EListError = class(Exception);
-{$endif}
+  EListError = {$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}SysUtils.EListError;
   EBitsError = class(Exception);
   EStringListError = class(Exception);
   EComponentError = class(Exception);

+ 1 - 1
rtl/objpas/rtlconst.inc

@@ -580,7 +580,7 @@ ResourceString
   sCannotManuallyConstructDevice = 'Manual construction of TDeviceInfo is not supported'; 
   SArgumentOutOfRange = 'Argument out of range';
   StrNoClientClass = 'The client cannot be an instance of the class %s';  
-  ListIndexErrorExt = 'List index out of bounds (%0:d).  %2:s object range is 0..%1:d';
+  SListIndexErrorExt = 'List index out of bounds (%0:d).  %2:s object range is 0..%1:d';
   
   { Classes observer support }
   SErrNotIObserverInterface = 'Interface is not an IObserver interface';

+ 1 - 0
rtl/objpas/sysconst.pp

@@ -149,6 +149,7 @@ const
   SFullpattern                  = 'Couldn''t match entire pattern string. Input too short at pattern position %d.';
   SPatternCharMismatch          = 'Pattern mismatch char "%s" at position %d.';
   SAMPMError                    = 'Hour >= 13 not allowed in AM/PM mode.';
+  SErrListIndexExt              = 'List index out of bounds (%d): %s object range is 0..%d';
 
   SShortMonthNameJan = 'Jan';
   SShortMonthNameFeb = 'Feb';

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

@@ -242,6 +242,7 @@ type
    EInvalidOpException = class(Exception);
 
    ENoConstructException = class(Exception);
+   EListError = Class(Exception);
 
    { Exception handling routines }
    function ExceptObject: TObject;
@@ -253,7 +254,7 @@ type
    procedure ShowException(ExceptObject: TObject; ExceptAddr: Pointer);
    procedure Abort;
    procedure OutOfMemoryError;
-
+   procedure ListIndexError(aIndex,aMax: Integer; aObj: TObject);
 
 Type
    TBeepHandler = Procedure;

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

@@ -628,6 +628,20 @@ begin
   Raise OutOfMemory;
 end;
 
+procedure ListIndexError(aIndex,aMax: Integer; aObj: TObject);
+
+var
+ aClassName : string;
+
+begin
+  if Assigned(aObj) then
+    aClassName:=aObj.ClassName
+  else
+    aClassName:='<nil>';  
+  Raise EListError.CreateFmt(SErrListIndexExt,[aIndex,aClassName,aMax])
+end;
+
+
 { ---------------------------------------------------------------------
     Initialization/Finalization/exit code
   ---------------------------------------------------------------------}
@@ -1195,3 +1209,5 @@ class function TOSVersion.ToString: string; static;
 begin
   Result:=FFull;
 end;
+
+