Problem with an empty collection

9 views
Skip to first unread message

Luis Enrique Pettinari

unread,
Jan 18, 2026, 8:43:17 PMJan 18
to Spring4D
Hi,
I have the following method:

function TCompraOperadoraPedidoDAO.GetPedidosColetados(
  aCodCompraOperadora: Integer): ICollection<TIdPedidoAlocacao>;
var
  Query: IQuery;
begin
  Result := TCollections.CreateList<TIdPedidoAlocacao>;

  Query := GetQuery;
  Query.SQL.Add('SELECT PF.CODPEDIDO, PF.CODCLIENTE_ALOCACAO, MIN(coalesce(CO.COLETADA, ''S'')) COLETADA');
  ...
  Query.Open;

  while not Query.Eof do
    begin
    if Query.FieldByName('COLETADA').AsString = 'S' then
      Result.Add(TIdPedidoAlocacao.Create(Query.FieldByName('CODPEDIDO').AsInteger,
                                          Query.FieldByName('CODCLIENTE_ALOCACAO').AsInteger));

    Query.Next;
    end;
end;


That is used as

PedidosColetados := GetPedidosColetados(Codigo.ToInteger);
  for PedidoAlocacao in PedidosColetados do
    uPedidoSituacao.MarcaPedidoFilialColetado(PedidoAlocacao.CodPedido,
                                                                                     PedidoAlocacao.CodClienteAlocacao);

I noticed that even when PedidosColetados is empty it enters the loop. What am I doing wrong? Do I need to explicitly check if the collection is not empty?

Thanks in advance;

Reply all
Reply to author
Forward
0 new messages