|
|
@@ -84,13 +84,15 @@ type |
|
|
|
public type |
|
|
|
TEnumerator = class(TObject) |
|
|
|
private |
|
|
|
fReverse: Boolean; |
|
|
|
fList: TFPList; |
|
|
|
fPosition: Integer; |
|
|
|
function GetCurrent: T; |
|
|
|
public |
|
|
|
property Current: T read GetCurrent; |
|
|
|
function GetEnumerator: TEnumerator; |
|
|
|
function MoveNext: Boolean; |
|
|
|
constructor Create(const aList: TFPList); |
|
|
|
constructor Create(const aList: TFPList; const aReverse: Boolean = false); |
|
|
|
end; |
|
|
|
|
|
|
|
private |
|
|
@@ -111,9 +113,10 @@ type |
|
|
|
procedure DeleteIntern(const aIndex: Integer; const aFreeItem: Boolean = true); |
|
|
|
|
|
|
|
public |
|
|
|
property OwnsObjects: Boolean read fOwnsObjects write fOwnsObjects; |
|
|
|
property OwnsObjects: Boolean read fOwnsObjects write fOwnsObjects; |
|
|
|
|
|
|
|
function GetEnumerator: TEnumerator; |
|
|
|
function GetReverseEnumerator: TEnumerator; |
|
|
|
procedure Clear; |
|
|
|
|
|
|
|
constructor Create(const aOwnsObjects: Boolean = true); |
|
|
@@ -703,19 +706,34 @@ begin |
|
|
|
result := PListItem(fList[fPosition])^.data; |
|
|
|
end; |
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
function TutlListBase.TEnumerator.GetEnumerator: TEnumerator; |
|
|
|
begin |
|
|
|
result := self; |
|
|
|
end; |
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
function TutlListBase.TEnumerator.MoveNext: Boolean; |
|
|
|
begin |
|
|
|
inc(fPosition); |
|
|
|
result := (fPosition < fList.Count) |
|
|
|
if fReverse then begin |
|
|
|
dec(fPosition); |
|
|
|
result := (fPosition >= 0); |
|
|
|
end else begin |
|
|
|
inc(fPosition); |
|
|
|
result := (fPosition < fList.Count) |
|
|
|
end; |
|
|
|
end; |
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
constructor TutlListBase.TEnumerator.Create(const aList: TFPList); |
|
|
|
constructor TutlListBase.TEnumerator.Create(const aList: TFPList; const aReverse: Boolean); |
|
|
|
begin |
|
|
|
inherited Create; |
|
|
|
fList := aList; |
|
|
|
fPosition := -1; |
|
|
|
fReverse := aReverse; |
|
|
|
if fReverse then |
|
|
|
fPosition := fList.Count |
|
|
|
else |
|
|
|
fPosition := -1; |
|
|
|
end; |
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
@@ -808,7 +826,13 @@ end; |
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
function TutlListBase.GetEnumerator: TEnumerator; |
|
|
|
begin |
|
|
|
result := TEnumerator.Create(fList); |
|
|
|
result := TEnumerator.Create(fList, false); |
|
|
|
end; |
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
function TutlListBase.GetReverseEnumerator: TEnumerator; |
|
|
|
begin |
|
|
|
result := TEnumerator.Create(fList, true); |
|
|
|
end; |
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|