Content deleted Content added
GreenC bot (talk | contribs) |
Swapped order of code samples in Delphi section (modern is more important than old.) Tweaked grammar slightly. |
||
Line 213:
=== [[Borland Delphi|Delphi]] ===
Delphi
Versions of Delphi prior to 2009 do not offer direct support for associative arrays. However, you can simulate associative arrays using TStrings object. Here's an example:▼
<source lang=Delphi>▼
uses▼
SysUtils,▼
Generics.Collections;▼
var▼
PhoneBook: TDictionary<string, string>;▼
Entry: TPair<string, string>;▼
begin▼
PhoneBook := TDictionary<string, string>.Create;▼
PhoneBook.Add('Sally Smart', '555-9999');▼
PhoneBook.Add('John Doe', '555-1212');▼
PhoneBook.Add('J. Random Hacker', '553-1337');▼
for Entry in PhoneBook do▼
Writeln(Format('Number for %s: %s',[Entry.Key, Entry.Value]));▼
end.▼
</source>▼
▲Versions of Delphi prior to 2009 do not offer direct support for associative arrays. However, you can simulate associative arrays using the TStrings
<source lang=Delphi>
Line 238 ⟶ 259:
DataField.Free;
end;
▲</source>
▲Delphi 2009 introduced support for generics as well as several standard generic containers, including TDictionary.
▲<source lang=Delphi>
▲uses
▲ SysUtils,
▲ Generics.Collections;
▲var
▲ PhoneBook: TDictionary<string, string>;
▲ Entry: TPair<string, string>;
▲begin
▲ PhoneBook := TDictionary<string, string>.Create;
▲ PhoneBook.Add('Sally Smart', '555-9999');
▲ PhoneBook.Add('John Doe', '555-1212');
▲ PhoneBook.Add('J. Random Hacker', '553-1337');
▲ for Entry in PhoneBook do
▲ Writeln(Format('Number for %s: %s',[Entry.Key, Entry.Value]));
▲end.
</source>
|