mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-23 15:31:41 +02:00
* Implemented IndexOfItem, reversed search again in IndexOf
git-svn-id: trunk@19279 -
This commit is contained in:
parent
05c83ab538
commit
4a8914cbb0
rtl/objpas/classes
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user