Sign in Join
Wiki copytemporary

TFPGMap: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: TFPGMap

OldNewLine
1+TFPGMap is part of the `FGL` (Free Generics Library).
2+
3+## Example
4+
5+``` pascal
6+uses
7+ fgl;
8+
9+type
10+ TMyDict = specialize TFPGMap<string, integer>;
11+var
12+ Dict: TMyDict;
13+ Value: Integer;
14+begin
15+ Dict := TMyDict.Create;
16+ try
17+ Dict.Add('VarName', 99);
18+ ...
19+ Value := Dict['VarName'];
20+ ...
21+ finally
22+ Dict.Free;
23+ end;
24+end;
25+```
26+
27+## IndexOfData
28+
29+By default `TFPGMap<>` does not provide a comparison for the Data type. So method IndexOfData will not find anything. You need to provide it by assigning the OnDataCompare event:
30+
31+``` pascal
32+uses
33+ StrUtils, fgl;
34+
35+{$R *.lfm}
36+
37+type
38+ TMyTest = specialize TFPGMap<PtrInt, String>;
39+...
40+ private
41+ FMyTest: TMyTest;
42+ ...
43+ public
44+ property MyTest: TMyTest read FMyTest write SetMyTest;
45+ end;
46+...
47+
48+function CompareStringFunc(const aData1, aData2: String): Integer;
49+begin
50+ Result := AnsiCompareStr(aData1, aData2);
51+end;
52+
53+procedure TForm1.FormCreate(Sender: TObject);
54+begin
55+ FMyTest:= TMyTest.Create;
56+ FMyTest.OnDataCompare := @CompareStringFunc;
57+```
58+
59+## See also
60+
61+- [Free Pascal docs on TFPGMap](https://www.freepascal.org/docs-html/current/rtl/fgl/tfpgmap.html)
62+
63+---
64+*From the Free Pascal wiki, page "TFPGMap", as it stood on 2022-11-13 after a change by Alextp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history