Buenas, resulta que tengo un listbox que se llena de una base de datos de pacientes, el codigo es el siguiente
Código:
While not zQuery1.eof do
begin
pa.id_paciente:= zQuery1.FieldByName('id_paciente').AsInteger;
pa.Apellido:=zQuery1.FieldByName('apellido').AsString;
pa.Nombre:=zQuery1.FieldByName('nombre').AsString;
pa.dni:=zQuery1.FieldByName('dni').AsInteger;
pa.obra_social:=zQuery1.FieldByName('obra_social').AsString;
pa.fecha_nac:=zQuery1.FieldByName('fecha_nacimiento').AsString;
pa.ciudad:=zQuery1.FieldByName('ciudad').AsString;
pa.dir:=zQuery1.FieldByName('direccion').AsString;
pa.tel:=zQuery1.FieldByName('telefono').AsInteger;
pa.email:=zQuery1.FieldByName('email').AsString;
listaPacientes.Items.AddObject(pa.Apellido+' '+pa.Nombre,pa);
zQuery1.Next;
end;
el problema esta en el momento de recuperar los objetos almacenados con el siguiente codigo,
Código:
if(listaPacientes.ItemIndex>-1)then
begin
pa:=(listaPacientes.Items.Objects[listaPacientes.ItemIndex]) as tpaciente;
paApellido.Text:= pa.Apellido;
paNombre.Text:=pa.Nombre;
paDNI.Text:=IntToStr(pa.dni);
paObraSocial.Text:=pa.obra_social;
paCiu.Text:=pa.ciudad;
paTel.Text:=IntToStr(pa.tel);
paMail.Text:=pa.email;
end;
simpre me recupera el ultimo elemento almacenado, por mas que utilice un indice constante
Código Delphi
[-]listaPacientes.Items.Objects[1];
Espero me puedan ayudar, saludos