1. Home
  2. Computing & Technology
  3. Delphi Programming
Delphi for .NET FCL Examples Reference
Stack namespace
System.Collections
Declaration
Stack = class(System.Object, ICollection, IEnumerable, ICloneable);
Description
Represents a simple last-in-first-out collection of objects.
Example
program System_Collections_Stack;
{$APPTYPE CONSOLE}
{$AUTOBOX ON}

uses System.Collections;

type
 SamplesStack = class
 public
  class procedure Main;
 private
  class procedure PrintValues(myCollection: IEnumerable);
 end;

{ SamplesStack }

class procedure SamplesStack.Main;
var
  myStack: Stack;
begin
  // Creates and initializes a new Stack.
  myStack := Stack.Create;
  myStack.Push('Hello');
  myStack.Push('World');
  myStack.Pop;
  myStack.Push('Delphi for .NET');
  myStack.Push('World');

  // Displays the properties and values of the Stack
  Console.WriteLine('myStack');
  Console.WriteLine(''#9'Count:    {0}', myStack.Count);
  Console.Write(''#9'Values:');

  PrintValues(myStack);
end;

class procedure SamplesStack.PrintValues
                (myCollection: IEnumerable);
var
  myEnumerator: IEnumerator;
begin
  myEnumerator := myCollection.GetEnumerator;
  while myEnumerator.MoveNext do
  begin
    Console.Write(''#9'{0}',
                  myEnumerator.Current);
  end;
  Console.WriteLine;
end;

//test program
begin
  SamplesStack.Main;
end.
Example output
myStack
    Count:    3
    Values:    World   Delphi for .NET   Hello

Looking for Delphi for .NET examples? Look no further, Delphi for .NET FCL Examples Reference is what you are looking for!

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.