Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 14-10-2011
chueco chueco is offline
Registrado
NULL
 
Registrado: sep 2011
Posts: 6
Poder: 0
chueco Va por buen camino
recuperar Objects de ListBox

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
Responder Con Cita
  #2  
Antiguo 14-10-2011
Avatar de olbeup
olbeup olbeup is offline
Miembro
 
Registrado: jul 2005
Ubicación: Santiago de la Ribera (España)
Posts: 685
Poder: 19
olbeup Va camino a la fama
Para hacer lo que quiere tienes que hacer que "pa" sea un objecto.

Código Delphi [-]
type
  TPa = class
    private
      Fid_paciente: Integer;
      FApellido: String;
      FNombre: String;
      Fdni: Integer;
      Fobra_social: String;
      Ffecha_nac:String;
      Fciudad: String;
      Fdir: String;
      Ftel: Integer;
      Femail: String;
    public
      property id_paciente: Integer read fid_paciente write fid_paciente;
      property Apellido: String read FApellido write FApellido;
      property Nombre: String read FNombre write FNombre;
      property dni: Integer read Fdni write Fdni;
      property obra_social: String read Fobra_social write Fobra_social;
      property fecha_nac:String read Ffecha_nac write Ffecha_nac;
      property ciudad: String read Fciudad write Fciudad;
      property dir: String read Fdir write Fdir;
      property tel: Integer read Ftel write Ftel;
      property email: String read Femail write Femail;
  end;

var
  pa: TPa;
Después haces
Código Delphi [-]
While not zQuery1.eof do
begin
 pa := TPa.Create;
 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;

y luego
Código Delphi [-]
if(listaPacientes.ItemIndex>-1)then
begin
pa:=TPa(listaPacientes.Items.Objects[listaPacientes.ItemIndex]);

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;
Espero que te sirva
Un saludo.

Última edición por olbeup fecha: 14-10-2011 a las 09:02:57.
Responder Con Cita
  #3  
Antiguo 14-10-2011
Avatar de olbeup
olbeup olbeup is offline
Miembro
 
Registrado: jul 2005
Ubicación: Santiago de la Ribera (España)
Posts: 685
Poder: 19
olbeup Va camino a la fama
Y cuando cierras el formulario
Código Delphi [-]
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
  nI: Integer;
begin
  for nI := 0 to (listaPacientes.Count -1) do
    TPa(ListPacientes.Items.Objects[nI]).Free;
end;
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
agregar y/o eliminar items de un listbox a partir de otro listbox Goyo PHP 2 27-09-2007 16:46:30
Enterprise Core Objects edalmasso .NET 13 23-04-2007 17:58:08
Oracle Objects for OLE SMTZ Oracle 0 16-08-2005 09:37:00
IB Objects douglascosta Conexión con bases de datos 1 28-04-2005 02:19:47
Large Objects en PostgreSQL gatosoft MySQL 1 28-05-2004 21:32:35


La franja horaria es GMT +2. Ahora son las 00:55:23.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi