* Implemented IndexOfItem, reversed search again in IndexOf

git-svn-id: trunk@19279 -
This commit is contained in:
michael 2011-09-29 07:50:24 +00:00
parent 05c83ab538
commit 4a8914cbb0
2 changed files with 36 additions and 3 deletions
rtl/objpas/classes

View File

@ -179,6 +179,11 @@ type
function MoveNext: Boolean;
property Current: Pointer read GetCurrent;
end;
{$ifdef VER2_4}
type
TDirection = (FromBeginning, FromEnd);
{$endif}
TFPList = class(TObject)
private
@ -200,6 +205,10 @@ type
procedure SetCount(NewCount: Integer);
Procedure RaiseIndexError(Index: Integer);
public
{$IFNDEF VER2_4}
Type
TDirection = (FromBeginning, FromEnd);
{$ENDIF}
destructor Destroy; override;
Procedure AddList(AList : TFPList);
function Add(Item: Pointer): Integer; {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
@ -212,6 +221,7 @@ type
function First: Pointer;
function GetEnumerator: TFPListEnumerator;
function IndexOf(Item: Pointer): Integer;
function IndexOfItem(Item: Pointer; Direction: TDirection): Integer;
procedure Insert(Index: Integer; Item: Pointer); {$ifdef CLASSESINLINE} inline; {$endif CLASSESINLINE}
function Last: Pointer;
procedure Move(CurIndex, NewIndex: Integer);

View File

@ -197,10 +197,33 @@ begin
end;
function TFPList.IndexOf(Item: Pointer): Integer;
Var
C : Integer;
begin
Result:=Count-1;
while (Result >=0) and (Flist^[Result]<>Item) do
Result:=Result - 1;
Result:=0;
C:=Count;
while (Result<C) and (Flist^[Result]<>Item) do
Inc(Result);
If Result>=C then
Result:=-1;
end;
function TFPList.IndexOfItem(Item: Pointer; Direction: TDirection): Integer;
Var
C : Integer;
begin
if Direction=fromBeginning then
Result:=IndexOf(Item)
else
begin
Result:=Count-1;
while (Result >=0) and (Flist^[Result]<>Item) do
Result:=Result - 1;
end;
end;
procedure TFPList.Insert(Index: Integer; Item: Pointer);