Home  |  Delphi .net Home  |  System.Collections.SortedList  |  GetKeyList Method
  
GetKeyList  
Method  
Gets a read-only, dynamically updated list of current SortedList keys
SortedList Class
System.Collections NameSpace
CF1.  Function GetKeyList : IList;
CF : Methods with this mark are Compact Framework Compatible
Description
Gets a read-only Ilist of all the Keys in the current SortedList. The interesting and very useful aspect to this list is that it is hot-linked to the SortedList : changes to the latter are immediately reflected in the IList.
Microsoft MSDN Links
System.Collections
System.Collections.SortedList
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
Illustrating the dynamic nature of the returned Key list
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  MyList     : System.Collections.SortedList;
  KeyList    : System.Collections.IList;
  i          : Integer;

begin
  // Create our sorted list
  MyList := SortedList.Create;

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

  // Get a read only, dynamically updated list of keys
  KeyList := MyList.GetKeyList;

  // Display the key list :
  Console.WriteLine('KeyList at the start :');
  Console.WriteLine;
  for i := 0 to KeyList.Count-1 do
    Console.WriteLine(KeyList[i].ToString);

  // Now add a couple of entries
  MyList['Status'] := 'Single';
  MyList['Gender'] := 'Male';

  // Display the key list again :
  Console.WriteLine;
  Console.WriteLine('KeyList after updates :');
  Console.WriteLine;
  for i := 0 to KeyList.Count-1 do
    Console.WriteLine(KeyList[i].ToString);

  Console.Readline;
end.
   KeyList at the start :
  
   Age
   Birthday
   Name
  
   KeyList after updates :
  
   Age
   Birthday
   Gender
   Name
   Status
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author