Recent

Author Topic: Output all keys and values from TFPGMap  (Read 306 times)

LemonParty

  • Sr. Member
  • ****
  • Posts: 370
Output all keys and values from TFPGMap
« on: October 09, 2025, 07:33:46 pm »
Hello.

I want to output all keys and values from TFPGMap. How can I do that?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

cdbc

  • Hero Member
  • *****
  • Posts: 2467
    • http://www.cdbc.dk
Re: Output all keys and values from TFPGMap
« Reply #1 on: October 09, 2025, 07:56:32 pm »
Hi
Does it have an 'Iterate' method, then use that...
It usually requires you to provide a procedure or method to call for each item in the map...
Maybe it's called 'ForEach'... that would be the same M.O. as above.

Regards Benny

eta: Forget iterating that list or its ancestors...! Just had a look  %)
« Last Edit: October 09, 2025, 08:10:01 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6 -> FPC 3.2.2 -> Lazarus 4.0 up until Jan 2025 from then on it's both above &: KDE6/QT6 -> FPC 3.3.1 -> Lazarus 4.99

Thausand

  • Sr. Member
  • ****
  • Posts: 399
Re: Output all keys and values from TFPGMap
« Reply #2 on: October 09, 2025, 08:19:25 pm »
I want to output all keys and values from TFPGMap. How can I do that?
Code: Pascal  [Select][+][-]
  1. program test;
  2.  
  3. {$mode objfpc}{$h+}
  4.  
  5. uses sysutils,fgl;
  6. type TAMap = specialize TFPGMap<string,integer>;
  7. var
  8.   Map:TAMap;
  9.   n,i:integer;
  10. begin
  11.   Map:=TAMap.Create;
  12.   for n:=1 to 100 do Map.Add(n.ToString,n*2);
  13.   for i:=0 to Map.Count-1 do writeln(Map.Keys[i],' -> ',Map.Data[i]);
  14.   Map.Free;
  15. end.
  16.  

LemonParty

  • Sr. Member
  • ****
  • Posts: 370
Re: Output all keys and values from TFPGMap
« Reply #3 on: October 10, 2025, 02:26:44 pm »
It works. Thank you.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

 

TinyPortal © 2005-2018