Sign in Join
Wiki copytemporary

TFPGMap

TFPGMap is part of the FGL (Free Generics Library).

Example

pascal
uses
  fgl;
 
type
  TMyDict = specialize TFPGMap<string, integer>;
var
  Dict: TMyDict;
  Value: Integer;
begin
  Dict := TMyDict.Create;
  try
    Dict.Add('VarName', 99);
    ...
    Value := Dict['VarName'];
    ...
  finally
    Dict.Free;
  end;
end;

IndexOfData

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:

pascal
uses
  StrUtils, fgl;

{$R *.lfm}

type
  TMyTest = specialize TFPGMap<PtrInt, String>;
...
  private
    FMyTest: TMyTest;
  ...
  public
    property MyTest: TMyTest read FMyTest write SetMyTest;
  end;
...
 
function CompareStringFunc(const aData1, aData2: String): Integer;
begin
  Result := AnsiCompareStr(aData1, aData2);
end;
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  FMyTest:= TMyTest.Create;
  FMyTest.OnDataCompare := @CompareStringFunc;

See also


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.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.