mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-28 23:24:11 +02:00
+ Partial implementation of TList
This commit is contained in:
parent
749db24913
commit
f325d30461
@ -25,6 +25,9 @@
|
||||
function TList.Get(Index: Integer): Pointer;
|
||||
|
||||
begin
|
||||
If (Index<0) or (Index>Count) then
|
||||
Runerror (255);
|
||||
Result:=FList^[Index];
|
||||
end;
|
||||
|
||||
|
||||
@ -32,6 +35,7 @@ end;
|
||||
procedure TList.Grow;
|
||||
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
|
||||
@ -39,6 +43,11 @@ end;
|
||||
procedure TList.Put(Index: Integer; Item: Pointer);
|
||||
|
||||
begin
|
||||
if Index<0 then
|
||||
Runerror(255)
|
||||
While Index>Capacity do Grow;
|
||||
Flist[I^ndex]:=Item;
|
||||
If Index>Count then Count:=Index;
|
||||
end;
|
||||
|
||||
|
||||
@ -53,6 +62,16 @@ end;
|
||||
procedure TList.SetCount(NewCount: Integer);
|
||||
|
||||
begin
|
||||
If NewCount<0 then
|
||||
RunError(255);
|
||||
If NewCount<Count then
|
||||
FCount:=NewCount
|
||||
else
|
||||
begin
|
||||
While NewCount>Capacity do Grow;
|
||||
FillByte (Flist[count],(Newcount-Count)*SizeOF(Pointer),0);
|
||||
FCount:=Newcount;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
@ -68,7 +87,7 @@ end;
|
||||
Function TList.Add(Item: Pointer): Integer;
|
||||
|
||||
begin
|
||||
// Self.Insert (Count,Item);
|
||||
Self.Insert (Count,Item);
|
||||
end;
|
||||
|
||||
|
||||
@ -76,6 +95,13 @@ end;
|
||||
Procedure TList.Clear;
|
||||
|
||||
begin
|
||||
If Assigned(FList) then
|
||||
begin
|
||||
FreeMem (Flist,FCapacity);
|
||||
FList:=Nil;
|
||||
FCapacity:=nil;
|
||||
FCount:=Nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
@ -93,8 +119,12 @@ end;
|
||||
|
||||
procedure TList.Exchange(Index1, Index2: Integer);
|
||||
|
||||
var Temp1,Temp2 : Pointer;
|
||||
|
||||
begin
|
||||
Temp:=FList[Index1];
|
||||
Items[Index1]:=Items[Index2];
|
||||
Items[Index2]:=Temp;
|
||||
end;
|
||||
|
||||
|
||||
@ -103,19 +133,33 @@ function TList.Expand: TList;
|
||||
|
||||
|
||||
begin
|
||||
If Count=FCapacity then Grow;
|
||||
end;
|
||||
|
||||
|
||||
function TList.First: Pointer;
|
||||
|
||||
Var I : longint;
|
||||
|
||||
begin
|
||||
I:=0;
|
||||
Result:=Nil;
|
||||
While (I<Count-1) and (FList[I]=Nil) do Inc(i);
|
||||
Result:=FList[I];
|
||||
end;
|
||||
|
||||
|
||||
|
||||
function TList.IndexOf(Item: Pointer): Integer;
|
||||
|
||||
Var I : longint;
|
||||
|
||||
begin
|
||||
I:=0;
|
||||
Result:=-1;
|
||||
if Count=0 then exit;
|
||||
While (I<Count) and (Flist[I]<>Item) do Inc(I);
|
||||
If Flist[I]=Item then Result:=I;
|
||||
end;
|
||||
|
||||
|
||||
@ -123,13 +167,25 @@ end;
|
||||
procedure TList.Insert(Index: Integer; Item: Pointer);
|
||||
|
||||
begin
|
||||
If (Index<0) then
|
||||
RunError(255);
|
||||
While Index+1>Capacity do Grow;
|
||||
If Index<Count then
|
||||
Move (Flist[Index],Flist[Index+1],(Count-Index)*SizeOf(Pointer));
|
||||
Item[Index]:=Item;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
function TList.Last: Pointer;
|
||||
|
||||
Var I : longint;
|
||||
|
||||
begin
|
||||
I:=Count-1;
|
||||
Result:=Nil;
|
||||
While (I>-1) and (FList[I]=Nil) dec Inc(i);
|
||||
if I>-1 then Result:=FList[I];
|
||||
end;
|
||||
|
||||
|
||||
@ -142,11 +198,18 @@ end;
|
||||
function TList.Remove(Item: Pointer): Integer;
|
||||
|
||||
begin
|
||||
If (Index<0) or (Index>Count-1) then
|
||||
RunError(255);
|
||||
While Index+1>Capacity do Grow;
|
||||
System.Move (Flist[Index],Flist[Index+1],(Count-Index)*SizeOf(Pointer));
|
||||
Item[Index]:=Item;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
procedure TList.Pack;
|
||||
|
||||
|
||||
begin
|
||||
end;
|
||||
|
||||
@ -211,7 +274,10 @@ begin
|
||||
end;
|
||||
{
|
||||
$Log$
|
||||
Revision 1.1 1998-05-04 14:30:12 michael
|
||||
Revision 1.2 1998-05-04 15:54:07 michael
|
||||
+ Partial implementation of TList
|
||||
|
||||
Revision 1.1 1998/05/04 14:30:12 michael
|
||||
* Split file according to Class; implemented dummys for all methods, so unit compiles.
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user