| Description |
Add a Key-Value data pair to the current SortedList.
There are two other ways (shown in the example) of adding to the list :
Table.Item[Key] := Value
Table[Key] := Value
The latter is an abbreviated version of the former, allowed since Item is the main (indexed) property of SortedList.
|
| | Notes | Value may be null.
|
|
| Microsoft MSDN Links |
System.Collections
System.Collections.SortedList
|
|
|
| A simple example |
program Project1;
{$APPTYPE CONSOLE}
uses
System.Collections;
var
MyList : System.Collections.SortedList;
DictEntry : DictionaryEntry;
Enumerator : IEnumerator;
begin
// Create our sorted List
MyList := SortedList.Create;
// Add entries to it using 3 different but equivalent ways
MyList['FirstName'] := 'Neil';
MyList.Item['LastName'] := 'Moffatt';
MyList.Add('Profession', 'Computer Programmer');
// Add some other data types
MyList.Add('Age', TObject(47));
MyList.Add('Birthday', DateTime.Create(1957, 2, 18));
// Get an enumerator for the SortedList
Enumerator := MyList.GetEnumerator;
// Display the array contents using the enumerator
while Enumerator.MoveNext do
begin
DictEntry := DictionaryEntry(Enumerator.Current);
Console.WriteLine('{0} = {1}',
DictEntry.Key.ToString,
DictEntry.Value.ToString);
end;
Console.Readline;
end.
| | Show full unit code | Age = 47
Birthday = 18/02/1957 00:00:00
FirstName = Neil
LastName = Moffatt
Profession = Computer Programmer
|
| |
|
|
|