I created this object list with mormot and it does not let destroy the TList created after use:
type
TTesteVO = class
private
fcodigo : Integer;
fnome : String;
frespostas : String;
ftotal : Real;
published
property codigo : integer read fcodigo write fcodigo;
property nome : string read fnome write fnome;
property respostas : string read frespostas write frespostas;
property total : real read ftotal write ftotal;
end;
var
TesteVO : TTesteVO;
Lista : TList;
Itens : Integer;
begin
Lista := TList.Create();
for Itens := 1 to 10 do
begin
TesteVO := TTesteVO.Create;
TesteVO.codigo := Itens;
TesteVO.nome := 'Nome: ' + IntToStr(Itens);
TesteVO.total := Itens * 10;
Lista.Add(TesteVO);
end;
MemoJson.Lines.Text := JSONReformat(ObjectToJSON(Lista));
for Itens := 0 to Lista.Count - 1 do
TTesteVO(Lista.Items[Itens]).Free;
FreeAndNil(Lista);
Lista := JSONToObjectList(TTesteVO, MemoJson.Lines.Text);
try
for Itens := 0 to Lista.Count -1 do
begin
TesteVO := Lista[Itens];
end;
finally
for Itens := 0 to Lista.Count - 1 do
TTesteVO(Lista.Items[Itens]).Free;
FreeAndNil(Lista);
end;
end; end.
Error: "Invalid pointer operation" when running FreeAndNil (List);