Skip to content

Instantly share code, notes, and snippets.

@ik5
Created February 7, 2013 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ik5/4735148 to your computer and use it in GitHub Desktop.
Save ik5/4735148 to your computer and use it in GitHub Desktop.
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