Logo

Programming-Idioms

History of Idiom 13 > diff from v11 to v12

Edit summary for version 12 by :

Version 11

2015-08-21, 09:10:49

Version 12

2015-08-23, 23:52:03

Idiom #13 Iterate over map keys and values

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

Idiom #13 Iterate over map keys and values

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

Imports
uses fgl;
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.   
Doc URL
http://wiki.freepascal.org/Generics#fgl_unit