I'm trying to pass the reference of an object that is in a list to another list, without having to delete the object and updating the first list so that the object is no longer referenced in it.
The code is inside a thread , but when I try to pass the reference of the object and deleting from the list some error occurs and the list does not update the objects correctly.
Follow the code:
tthread.Queue(nil,
procedure
begin
if (ListaSala.Count < LimiteSala) and (ListaPessoas.Count > 0) then
begin
ListaSala.Add(ListaPessoas.Extract);
ListaPessoas.Items[ListaPessoas.Count-1] := nil;
ListaPessoas.Delete(ListaPessoas.Count-1);
if ListaSala.Count > 0 then
Memo1.Lines.Add(ListaSala.Items[ListaSala.Count-1].NomeToString() + ' entrou na sala');
end;
Label5.Text := ListaSala.Count.ToString;
end);
sleep(2*Segundo);
Any light?