Operator 'In' into TList<>

Issue #381 invalid
Max Max created an issue

why during the cycles of interactions on tlist with the 'in' operator item free memory?

type
  stack = class(TStack<Integer>)

  end;

procedure TForm1.btn1Click(Sender: TObject);
var
  Lista : TList<stack> ;
  var item : stack;
begin

    lista := TList<stack>.Create;
    item := stack.Create;

    item.Push(2);
    Lista.Add(item);


    for var x in lista do
        ShowMessage('interatore') ;

    for var x in lista do             // <<------ item not exist, in more case generate Exception
        ShowMessage('interatore') ;
end;

Thank you.

Comments (1)

  1. Stefan Glienke repo owner

    Because Spring collections are not meant to be used as objects but as interfaces. Use IStack and create via the factory method from TCollections.

  2. Log in to comment