laremi400 Master

Registrado: 12 May 2004Mensajes: 179
|
Publicado: Mie 22 Mar, 2006 3:43 pm Asunto: Definir objeto para ser liberado |
|
|
Hola!
Cuando se define un objeto en la manera Lista = new TListBox(this) se supone que la propiedad se la estas dando a this, quien se encargará de liberar la memoria cuando se libere el objeto.
Y se supone que si quieres ser tú quien liberes la memoria hay que pasarle un NULL, pero si lo hago me da un error.
¿Como hay que hacerlo?. Ahora mismo si hago un delete para eliminar este objeto me da un "Access violation..." etc.
| Código: |
//---------------------------------------------------------------------------
// Cuando se hace clic se le pasa el valor de la lista al textbox
// y se ¿borra? la lista.
//---------------------------------------------------------------------------
void __fastcall TIpaq::ListaClick(TObject* Sender)
{
if(Lista->ItemIndex >= 0) automatico->Text = Lista->Items->Strings[Lista->ItemIndex];
Lista->Visible = false; //en vez de delete
automatico->SetFocus();
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TIpaq::PceAutomaticoButtons(TObject *Sender,
TJfEditButton Button)
{
Ejecutar(Datos->Consulta,"Select distinct automatico "
"from Cliente where CliCIF = 'AXXX' and Enviado = 0 ");
if(Lista == NULL)
{
Lista = new TListBox(this);
Lista->Parent = this;
Lista->Left = automatico->Left;
Lista->Top = automatico->Top + (automatico->Height + 10);
Lista->Width = automatico->Width + 10; //se le suma 10 que será la barra de desplazamiento
Lista->Height = (Datos->Consulta->RecordCount+1) * Lista->ItemHeight;
if(Lista->Height+Lista->Top > this->Height) Lista->Height = this->Height - Lista->Top;
Lista->IntegralHeight = true;
Lista->Ctl3D = false;
Lista->Style = lbOwnerDrawVariable;
Lista->Font->Name = "Small Fonts";
Lista->Font->Size = 7;
Lista->OnClick = ListaClick;
}
if(Datos->Consulta->RecordCount > 0 && Lista != NULL)
{
Lista->Visible = True;
Lista->Clear();
Datos->Consulta->First();
while(!Datos->Consulta->Eof)
{
Lista->Items->Add(Datos->Consulta->FieldValues["automatico"]);
Datos->Consulta->Next();
} //fin while
} //si hay datos
}
//---------------------------------------------------------------------------
// cuando se activa la ventana se ponen los punteros a la lista a NULL
//---------------------------------------------------------------------------
void __fastcall TIpaq::FormActivate(TObject *Sender)
{
Lista = NULL;
} |
Gracias por tu tiempo. |
|