[Solved] Delphi: TThreadList sometimes lock program


You need to call LockList() outside of the try block instead of inside of it, eg:

function del_from_list(const id: string): boolean;
var
  List: TList;
  i : integer;
begin
  Result := False;
  List := global_list.LockList;
  try
    with List do
    begin
      for i :=0 to Count-1 do
      begin
        if Tthread_list(Items[i]).id = id then
        begin
          Delete(i);
          Result := True;
          break;
        end;
      end;
    end;
  finally
    global_list.UnlockList;
  end;
end;

9

solved Delphi: TThreadList sometimes lock program