Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,709 questions

55,473 answers

573 users

How to filter a map in Pascal

1 Answer

0 votes
program FilterMapExample;

uses
  FGL;

type
  TMyMap = specialize TFPGMap<Integer, String>;

var
  MyMap, FilteredMap: TMyMap;
  i: Integer;
begin
  // Initialize the map
  MyMap := TMyMap.Create;
  FilteredMap := TMyMap.Create;

  // Add key-value pairs
  MyMap.Add(1, 'A');
  MyMap.Add(2, 'B');
  MyMap.Add(3, 'C');
  MyMap.Add(4, 'D');
  MyMap.Add(5, 'E');

  // Filter the map: Keep only entries with even keys
  for i := 0 to MyMap.Count - 1 do
  begin
    if MyMap.Keys[i] mod 2 = 0 then
      FilteredMap.Add(MyMap.Keys[i], MyMap.Data[i]);
  end;

  for i := 0 to FilteredMap.Count - 1 do
    WriteLn('Key: ', FilteredMap.Keys[i], ', Value: ', FilteredMap.Data[i]);

  // Free memory
  MyMap.Free;
  FilteredMap.Free;
end.




(*
run:
  
Key: 2, Value: B
Key: 4, Value: D

*)

 



answered Aug 7, 2025 by avibootz
...