How to pass the reference of an object?

0

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?

    
asked by anonymous 06.12.2017 / 05:10

1 answer

0

I believe you will have to use ForceQueue instead of Queue , noting also that you will probably have to use Synchronize in your anonymous procedure, since you are updating external lists to the thread. You may want to consider creating an even full thread instance rather than an anonymous thread because you will have more resources to edit your lists, and you can pass them with var to the constructor parts parameters of the thread.     

17.12.2017 / 00:35