How to pass the reference of an object?

Asked

Viewed 298 times

0

I am trying to pass the reference of an object that is in a list to another list, without needing 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 object reference and delete from the list some error occurs and the list does not update the objects correctly.

Follows 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);

Some light?

  • Extract doesn’t just remove the item from the list? This set to nil and delete from the People List is really necessary?

  • tried to use Tobject ?

1 answer

0

I believe you’ll have to use ForceQueue instead of Queue, also noting that you will probably have to use Synchronize in your anonymous database, since you are updating external lists to the thread. Maybe you should consider creating a full thread instance, not an anonymous thread, because you’ll have more resources to edit your lists and you can pass them with var in the parameters of constructor thread.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.