In Delphi XE2, I need a generic object stack in which my calling code can access not just the top (via Peek), but Top-1, Top-2 etc. More of an "ObjectStackList" perhaps.
I haven't spotted a simple way to achieve that using the existing System.Generics.Collections classes. And TObjectStack's FItems is private in TStack, so no straightforward way to create a TObjectStack descendant which can access it.
I realize I could use ToArray to access items by index, but that creates a separate array which seems a waste of time and space just to access a single item in FItems.
Any ideas?
Just use TObjectList
instead. You can access all the elements you want, and you can modify it at whichever end you want to treat as the top of a stack.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With