Ver Mensaje Individual
  #23  
Antiguo 25-11-2020
Avatar de movorack
[movorack] movorack is offline
Miguel A. Valero
 
Registrado: feb 2007
Ubicación: Bogotá - Colombia
Posts: 1.346
Reputación: 20
movorack Va camino a la famamovorack Va camino a la fama
También puedes usar un TDictionary o crear tu propio objeto basado en este.

Código Delphi [-]
type
  TListaObjetos = class(TDictionary<String,Tobject>)
  public
    function Conteo: string;
  end;

function TListaObjetos.Conteo: string;
begin
  Result := Format('Tengo %d elementos', [Self.Count]);
end;

procedure TForm1.ListarObjetos(Sender: TObject);
  const
    //Algunos nombres están repetidos
    Nombres : Array [0..7] of string = ('Obj1', 'Obj2', 'Obj3', 'Obj1', 'Obj4', 'Obj2', 'Obj5', 'Obj1');
  var
    i: integer;
    ListaObjetos: TListaObjetos;
    Nombre: string;
begin
  ListaObjetos := TListaObjetos.Create;
  try
    for i := Low(Nombres) to High(Nombres) do
    begin
      Nombre := Nombres[i].Trim;

      if Nombre.IsEmpty or ListaObjetos.ContainsKey(Nombre.ToUpper) then
        Continue;

      ListaObjetos.Add(Nombre.ToUpper, TObject.Create);
    end;

    //En este punto se deben tener 5 objetos en la lista
    ShowMessage(ListaObjetos.Conteo);
  finally
    ListaObjetos.Free;
  end;
end;
__________________
Buena caza y buen remar... http://mivaler.blogspot.com
Responder Con Cita