Logo

Programming-Idioms

History of Idiom 13 > diff from v23 to v24

Edit summary for version 24 by :

Version 23

2015-09-13, 12:20:19

Version 24

2015-09-13, 12:22:30

Idiom #13 Iterate over map keys and values

Print each key k with its value x from an associative array mymap

Idiom #13 Iterate over map keys and values

Print each key k with its value x from an associative array mymap

Imports
uses fgl;
Imports
uses fgl;
type TMyMap = specialize TFPGMap<String, Integer>;
Code
type TMyMap = specialize TFPGMap<String, Integer>;

var
  mymap: TMyMap;
  i: Integer;

begin
  mymap := TMyMap.Create;

  mymap['one'] := 1;
  mymap['two'] := 2;

  for i := 0 to mymap.Count - 1 do
    WriteLn(mymap.Keys[i], '=', mymap.Data[i]);
end.   
Code
for i := 0 to mymap.Count - 1 do
  WriteLn(mymap.Keys[i], '=', mymap.Data[i]);
Doc URL
http://wiki.freepascal.org/Generics#fgl_unit
Doc URL
http://wiki.freepascal.org/Generics#fgl_unit