Home  |  Delphi .net Home  |  System.Collections.SortedList  |  Clear Method
Clear  
Method  
Clear (remove) all key-value data pairs from the current SortedList
SortedList Class
System.Collections NameSpace
CF1.  Procedure Clear ( ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
Removes all entries from the SortedList. The Count value is reset to zero. The capacity is unaffected.
Notes
Important : at the time of writing (using Delphi 8 Professional initial release), the Capacity incorrectly is reset to the default value of 16 by the Clear method.
Microsoft MSDN Links
System.Collections
System.Collections.SortedList
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  MyList     : System.Collections.SortedList;

begin
  // Create our sorted List
  MyList := SortedList.Create(10);

  // Add entries to it
  MyList['Name']     := 'Neil Moffatt';
  MyList['Age']      := TObject(47);
  MyList['Birthday'] := DateTime.Create(1957, 2, 18);

  Console.WriteLine('Count    = ' + MyList.Count.ToString);
  Console.WriteLine('Capacity = ' + MyList.Capacity.ToString);
  Console.WriteLine;
  Console.WriteLine('Clearing the SortedList :');

  // Clear the SortedList
  MyList.Clear;

  Console.WriteLine;
  Console.WriteLine('Count    = ' + MyList.Count.ToString);
  Console.WriteLine('Capacity = ' + MyList.Capacity.ToString);

  Console.Readline;
end.
Show full unit code
  Count    = 3
  Capacity = 10
  
  Clearing the SortedList :
  
  Count    = 0
  Capacity = 16    // This is incorrect (at the time of writing)
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author