Created
February 7, 2013 23:20
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{$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