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