Ver Mensaje Individual
  #3  
Antiguo 30-05-2014
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Reputación: 19
Angel.Matilla Va por buen camino
Gracias por la respuesta pero algo no funciona bien. Con el código que me has sugerido tengo esto:



Esto está sacado con el depurador una vez que se ha ejecutado la línea pItem = Selected ? Item : NULL;, y como pudes ver el caption de ambos elementos es distinto. He cambiado algo en el código desde el que llamo a este formulario, que es una pantalla de ayuda; ahora está así:
Código:
Application->CreateForm(__classid(TfSelMun), &fSelMun);
for (; !fSocios->Query->Eof; fSocios->Query->Next())
{
     pItem = fSelMun->Lista->Items->Add();
     pItem->Caption = fSocios->Query->FieldByName("Poblacion")->AsString;
     pItem->SubItems->Add(fSocios->Query->FieldByName("CodPostal")->AsString);
}

fSelMun->Lista->Items->Item[0]->Selected = true;
fSelMun->Lista->Selected->MakeVisible(true);
pItem = NULL;

if (fSelMun->Lista->Items->Count > 1)
     fSelMun->ShowModal();

if (pItem != NULL)
{
     if (Cpostal->Text.IsEmpty())
          Cpostal->Text = pItem->SubItems->Strings[0];
     Poblacion->Text = pItem->Caption;
}
delete fSelMun;
Y el cóigo en ese formulario fSelMun está así:
Código:
void __fastcall TfSelMun::ListaSelectItem(TObject *Sender, TListItem *Item, bool Selected)
{
     Button1->Enabled = false;
     pItem = Selected ? Item : NULL;

     if (Selected)
          Button1->Enabled = true;
}
Lo cierto es que si denjo la línea del ShowMessage para comprobar los valores puedo ver esto:



Siendo ese el registro que está realmente seleccionado en el ListView, pero cuando vuelvo al formulario desde el que se ha llamado ¡pItem viene vacío! He probado usando una variable auxiliar y curiosamente me funciona bien, pero es ya más una cuestión de orgullo.
Responder Con Cita