thank you all for suggestions
@Thaddy and @PascalDragon
yes the question is I only have a pointer and no other info
anyway what I need is: instead of this
var i: integer
begin
i := 5;
writeln('integer I =', i);
end;
I want to write this
var ms: TMemoryspace;
begin
ms:=TMemoryspace.Create;
// property TMemoryspace.Integers wraps TNullableIntegers using Getter and Setter
ms.Integers['i'] := 5;
writeln('integer I =',ms.Integers['i']);
ms.Free;
end;
thus I know what type I need to have a value
but don't know at dispose time
@engkin
yes, your suggestion about use FreeMem works
following code works fine
program test_hashlist_nullable;
uses sysutils, nullable, Contnrs;
procedure TestNullable;
type
TNullString = specialize TNullable<String>;
PNullString = ^TNullString;
TNullInteger= specialize TNullable<Integer>;
PNullInteger = ^TNullInteger;
var nullint: PNullInteger;
nullstr: PNullString;
i: integer;
HashList: TFPHashList;
begin
WriteLn('Start');
HashList:=TFPHashList.Create;
try
// set values
nullstr:=new(PNullString);
nullstr^:='value 1';
HashList.Add('one', nullstr);
nullint:=new(PNullInteger);
nullint^:=2;
HashList.Add('two', nullint);
// write
WriteLn('one = ', PNullString(HashList.Find('one'))^.Value);
WriteLn('two = ', PNullInteger(HashList.Find('two'))^ .Value);
// free values
for i := 0 to HashList.Count -1 do begin
try
WriteLn('Dispose ' + i.ToString);
// Dispose( PNullString(HashList[i]) );
FreeMem(HashList[i]);
except
on e: exception do begin
WriteLn('Error during sispose (' + i.ToString + '):' + e.Message);
end;
end;
end;
finally
// free resources
FreeAndNil(HashList);
WriteLn('Stop');
end;
end;
begin
TestNullable;
end.
anyway I think I'm going to store the type in order to have "schema"
thank you all again
nomorelogic