0
I created this object list with mormot and it won’t let you 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);
my problem occurs in this section: List := Jsontoobjectlist(Ttestevo, Memojson.Lines.Text); Try for Items := 0 to List.Count -1 of Begin Test := List[Items]; end; Finally for Items := 0 to List.Count - 1 of Ttestevo(List.Items[Items]). Free; Freeandnil(List); end;
– Aparecido Silva