1. Home
  2. Computing & Technology
  3. Delphi Programming
Delphi for .NET FCL Examples Reference
ArrayList namespace
System.Collections
Declaration
ArrayList = class(System.Object, IList, ICollection, IEnumerable, ICloneable);
Description
Implements the IList interface using an array whose size is dynamically increased as required.
Example
program System_Collections_ArrayList;
{$APPTYPE CONSOLE}
{$AUTOBOX ON}

uses
  System.Collections;

type
  SamplesArrayList = class
  public
    class procedure Main;
  private
    class procedure PrintValues(myList: IEnumerable);
  end;

{ SamplesArrayList }
class procedure SamplesArrayList.Main;
var
  myAL: ArrayList;
begin
  // Creates and initializes a new ArrayList
  myAL := ArrayList.Create;
  myAL.Add('Hello');
  myAL.Add('Delphi for .Net');
  myAL.Add('World');
  myAL.Add('!');

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

  //Print out ArrayList
  PrintValues(myAL);
end;

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

//test program
begin
  SamplesArrayList.Main;
end.
Example output
myAL
    Count:    4
    Capacity: 16
    Values:   Hello  Delphi for .Net  World !

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.