hi
I coding for a listbox and afindbox.
But a error launch when my program exit.
I debug my program, I find that do the code below, the error should launch.
// Destructor
CLookupContainer::~CLookupContainer()
{
if(iEngine)
{
delete iEngine;
}
if(iFindBox)
delete iFindBox;
if(iListBox)
delete iListBox; // the error launch when step this line.
if(iCnvCharacterSetConverter)
{
delete iCnvCharacterSetConverter;
}
}
My codes about the main program below:
Please see them,
and give me some suggestion.
Thank you very much.
in the .h file
I define the two object.
private: //data
CEikTextListBox * iListBox;
CAknSearchField* iFindBox;
in the .cpp file,
the main codes about the program below;
please see them.
void CLookupContainer::ConstructL(const TRect& aRect)
{
iCnvCharacterSetConverter = CCnvCharacterSetConverter::NewL();
//CCnvCharacterSetConverter::TAvailability avail = CCnvCharacterSetConverter::EAvailable;
CreateWindowL();
if ( iListBox )
{
delete iListBox;
iListBox = NULL;
}
//iListBox = new( ELeave ) CAknSingleStyleListBox ();
iListBox = new( ELeave ) CAknDoubleStyleListBox();
iEngine = CExporterEngine::NewL(CEikonEnv::Static()->FsSession());
iEngine->GetMessagesL(iCallBack);
CAknSearchField::TSearchFieldStyle style(CAknSearchField::EFixed);
//style = CAknSearchField::EFixed;EPopup
if ( iListBox )
{
// Constructs listbox.
iListBox->ConstructL( this, 0 );
iListBox->Model()->SetItemTextArray( iEngine->iTextArray );
iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
}
iFindBox = CreateFindBoxL(iListBox, iListBox->Model(), style);
if ( iFindBox)
{
iFindBox->MakeVisible( ETrue );
}
SetRect(aRect);
SizeChanged();
ActivateL();
}
// Destructor
CLookupContainer::~CLookupContainer()
{
if(iEngine)
{
delete iEngine;
}
if(iFindBox)
delete iFindBox;
if(iListBox)
delete iListBox;
if(iCnvCharacterSetConverter)
{
delete iCnvCharacterSetConverter;
}
}
// ---------------------------------------------------------
// CLookupContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CLookupContainer::SizeChanged()
{
if ( iListBox )
{
if ( iFindBox )
{
SizeChangedForFindBox(); // Sets rectangle of listbox with findbox.
}
else
{
iListBox->SetRect( Rect() ); // Sets rectangle of listbox.
}
}
}
// ---------------------------------------------------------
// CLookupContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CLookupContainer::CountComponentControls() const
{
return 2; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CLookupContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CLookupContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iListBox;
case 1:
return iFindBox;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CLookupContainer:raw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CLookupContainer:raw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbWhite);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
// ---------------------------------------------------------
// CLookupContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CLookupContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
// TODO: Add your control event handler code here
}
TKeyResponse CLookupContainer::OfferKeyEventL(
const TKeyEvent& aKeyEvent,
TEventCode aType )
{
if ( aType != EEventKey ) // Is not key event?
{
return EKeyWasNotConsumed;
}
if ( iListBox )
{
if ( iFindBox )
{
TBool needRefresh( EFalse );
TBool flagsOfPopup( EFalse );
// Offers the key event to find box.
if ( AknFind::HandleFindOfferKeyEventL( aKeyEvent, aType, this,
iListBox, iFindBox,
flagsOfPopup,
needRefresh ) ==
EKeyWasConsumed )
{
if ( needRefresh )
{
iListBox->SetCurrentItemIndex(0);
iListBox->HandleItemAdditionL();
SizeChanged();
DrawNow();
}
return EKeyWasConsumed;
}
}
return iListBox->OfferKeyEventL( aKeyEvent, aType );
}
else
{
return EKeyWasNotConsumed;
}
}
// ----------------------------------------------------------------------------
// CAknExListColumnContainer::SizeChangedForFindBox()
// Called by framework when the view size is changed for creating listbox with
// findbox.
// ----------------------------------------------------------------------------
//
void CLookupContainer::SizeChangedForFindBox()
{
if ( iListBox && iFindBox )
{
TInt findWindowResourceId( R_AVKON_FIND_PANE );
TInt listAreaResourceId( R_AVKON_LIST_GEN_PANE_X );
TInt findWindowParentId( R_AVKON_MAIN_PANE_PARENT_NONE );
TBool flagsOfPopup( EFalse ); // Flag for find popup.
/*
TInt findWindowResourceId( R_AVKON_POPUP_FIND_WINDOW_COVER );
TInt listAreaResourceId( R_AVKON_LIST_GEN_PANE ); //R_AVKON_LIST_GEN_PANE
TInt findWindowParentId( R_AVKON_MAIN_PANE_PARENT_NONE );
TBool flagsOfPopup( EFalse ); // Flag for find popup.
*/
AknFind::HandleFindSizeChanged(
this, iListBox, iFindBox, flagsOfPopup, findWindowResourceId,
listAreaResourceId, R_AVKON_LIST_GEN_PANE_WITH_FIND_POPUP,
findWindowParentId );
//AknFind::HandleFindSizeChanged(this, iListBox, iFindBox);
}
}
CAknSearchField* CLookupContainer::CreateFindBoxL(
CEikListBox* aListBox,
CTextListBoxModel* aModel,
CAknSearchField::TSearchFieldStyle aStyle )
{
CAknSearchField* findbox = NULL;
if ( aListBox && aModel )
{
// Gets pointer of CAknFilteredTextListBoxModel. CTextListBoxModel
model = STATIC_CAST( CAknFilteredTextListBoxModel*, aModel );
// Creates FindBox.
findbox = CAknSearchField::NewL( *this,
aStyle,
NULL,
20 );
CleanupStack::PushL(findbox);
// Creates CAknListBoxFilterItems class.
model->CreateFilterL( aListBox, findbox );
//Filter can get by model->Filter();
CleanupStack::Pop(findbox); // findbox
}
return findbox;
}

raw(const TRect& aRect) const
Reply With Quote


