mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-03 06:49:26 +01:00
* Introduce TFPList.CheckIndex (bug ID 30887)
git-svn-id: trunk@34873 -
This commit is contained in:
parent
aa6a8acb72
commit
2e3ab0d37e
@ -230,7 +230,8 @@ Type
|
||||
procedure Put(Index: Integer; Item: Pointer); {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
|
||||
procedure SetCapacity(NewCapacity: Integer);
|
||||
procedure SetCount(NewCount: Integer);
|
||||
Procedure RaiseIndexError(Index: Integer);
|
||||
Procedure RaiseIndexError(Index: Integer); deprecated;
|
||||
Procedure CheckIndex(AIndex : Integer); {$ifdef CLASSESINLINE} inline;{$ENDIF}
|
||||
public
|
||||
Type
|
||||
TDirection = (FromBeginning, FromEnd);
|
||||
|
||||
@ -45,20 +45,26 @@ Const
|
||||
|
||||
procedure TFPList.RaiseIndexError(Index : Integer);
|
||||
begin
|
||||
// We should be able to remove this, but unfortunately it is marked protected.
|
||||
Error(SListIndexError, Index);
|
||||
end;
|
||||
|
||||
Procedure TFPList.CheckIndex(AIndex : Integer);
|
||||
|
||||
begin
|
||||
If (AIndex < 0) or (AIndex >= FCount) then
|
||||
Error(SListIndexError, AIndex); // Don't use RaiseIndexError, exception address will be better if we use error.
|
||||
end;
|
||||
|
||||
function TFPList.Get(Index: Integer): Pointer;
|
||||
begin
|
||||
If (Index < 0) or (Index >= FCount) then
|
||||
RaiseIndexError(Index);
|
||||
CheckIndex(Index);
|
||||
Result:=FList^[Index];
|
||||
end;
|
||||
|
||||
procedure TFPList.Put(Index: Integer; Item: Pointer);
|
||||
begin
|
||||
if (Index < 0) or (Index >= FCount) then
|
||||
RaiseIndexError(Index);
|
||||
CheckIndex(Index);
|
||||
Flist^[Index] := Item;
|
||||
end;
|
||||
|
||||
@ -140,8 +146,7 @@ end;
|
||||
|
||||
procedure TFPList.Delete(Index: Integer);
|
||||
begin
|
||||
If (Index<0) or (Index>=FCount) then
|
||||
Error (SListIndexError, Index);
|
||||
CheckIndex(Index);
|
||||
FCount := FCount-1;
|
||||
System.Move (FList^[Index+1], FList^[Index], (FCount - Index) * SizeOf(Pointer));
|
||||
// Shrink the list if appropriate:
|
||||
@ -163,10 +168,8 @@ procedure TFPList.Exchange(Index1, Index2: Integer);
|
||||
var
|
||||
Temp : Pointer;
|
||||
begin
|
||||
If ((Index1 >= FCount) or (Index1 < 0)) then
|
||||
Error(SListIndexError, Index1);
|
||||
If ((Index2 >= FCount) or (Index2 < 0)) then
|
||||
Error(SListIndexError, Index2);
|
||||
CheckIndex(Index1);
|
||||
CheckIndex(Index2);
|
||||
Temp := FList^[Index1];
|
||||
FList^[Index1] := FList^[Index2];
|
||||
FList^[Index2] := Temp;
|
||||
@ -256,10 +259,8 @@ procedure TFPList.Move(CurIndex, NewIndex: Integer);
|
||||
var
|
||||
Temp : Pointer;
|
||||
begin
|
||||
if ((CurIndex < 0) or (CurIndex > Count - 1)) then
|
||||
Error(SListIndexError, CurIndex);
|
||||
if ((NewIndex < 0) or (NewIndex > Count -1)) then
|
||||
Error(SlistIndexError, NewIndex);
|
||||
CheckIndex(CurIndex);
|
||||
CheckIndex(NewIndex);
|
||||
Temp := FList^[CurIndex];
|
||||
if NewIndex > CurIndex then
|
||||
System.Move(FList^[CurIndex+1], FList^[CurIndex], (NewIndex - CurIndex) * SizeOf(Pointer))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user