Home  |  Delphi .net Home  |  System.Collections.ArrayList  |  Remove Method
Remove  
Method  
Remove a particular Object Element from the ArrayList
ArrayList Class
System.Collections NameSpace
CF1.  Procedure Remove ( Value : Object; ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
The ArrayList is scanned from the start for a match to the Value object. If found, this first occurence is removed from the array.
 
The element Count is decremented by 1.
Notes
In the example, the string 'the' is removed. This relies on the fact that a string object in Delphi is said to equal another string object if the value is identical.
Microsoft MSDN Links
System.Collections
System.Collections.ArrayList
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  List : System.Collections.ArrayList;
  i    : Integer;

begin
  // Create our array list object
  List := ArrayList.Create;

  // Fill it with strings
  List.Add('the');
  List.Add('cat');
  List.Add('sat');
  List.Add('on');
  List.Add('the');
  List.Add('mat');

  // Display the contents : note the 0 indexing
  for i := 0 to List.Count-1 do
    Console.WriteLine(List.Item[i]);

  // Remove an element by value
  Console.WriteLine;
  List.Remove('the');

  // Display the contents : note the 0 indexing
  for i := 0 to List.Count-1 do
    Console.WriteLine(List.Item[i]);

  Console.Readline;
end.
Show full unit code
  the
  cat
  sat
  on
  the
  mat
  
  cat
  sat
  on
  the
  mat
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author