Hola sebamawa.
Si la lista ya está ordenada podes usar una búsqueda binaria. Tomemos como ejemplo una reducción de la clase que puso de ejemplo
roman:
Código Delphi
[-]
implementation
type
TCliente = class
Nombre: String;
end;
var
LstObj : TObjectList;
Cliente : TCliente;
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
LstObj := TObjectList.Create;
...
end;
function TForm1.BinarySearch(OLst: TObjectList; Valor: string): Integer;
var
Pri, Ult, Med : Integer;
Esta : boolean;
begin
Pri := 0;
Ult := OLst.Count-1;
Esta := False;
while (Pri <= Ult) and not Esta do
begin
Med := (Pri + Ult) div 2;
if TCliente(OLst.Items[Med]).Nombre = Valor then Esta := true;
if TCliente(OLst.Items[Med]).Nombre < Valor then Pri := Med + 1;
if TCliente(OLst.Items[Med]).Nombre > Valor then Ult := Med - 1;
end;
if Esta then
Result := Med
else
Result := -1;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
P : Integer;
begin
P := BinarySearch(LstObj, 'Juan Perez');
if P <> -1 then
ShowMessage('Nombre: ' + TCliente(LstObj.Items[P]).Nombre+#10#13+
'Posición: ' + IntToStr(P));
end;
...
procedure TForm1.FormDestroy(Sender: TObject);
begin
if Assigned(LstObj) then
LstObj.Free;
end;
Saludos.