Skip to content

Instantly share code, notes, and snippets.

@ik5 ik5/tfpsmap.pas
Created Feb 7, 2013

Embed
What would you like to do?
An example on how to properly use TFPSMap of FPC's fgl unit
{$mode objfpc}
uses sysutils, fgl;
type
TMyKey = class
public
Key : String;
constructor Create;
end;
TMyValue = class
public
Value : String;
constructor Create;
end;
constructor TMyKey.Create;
begin
Key := 'A Key';
end;
constructor TMyValue.Create;
begin
Value := 'A Value';
end;
var
Map : TFPSMap;
Key : TMyKey;
Value : TMyValue;
Value2 : TMyValue;
begin
Map := TFPSMap.create(SizeOf(key), SizeOf(Value));
Key := TMyKey.create;
Value := TMyValue.create;
Value.Value := 'here';
Map.add(@Key, @Value);
Value2 := TMyValue(Map.KeyData[@Key]^);
writeln(format('%P, %P, %S, %S', [Pointer(Value), Pointer(Value2),
Value.Value, Value2.value]));
Key.free;
Value.Free;
Map.free;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.