我想动态的加listbox的item,现在是添加可以,但退出程序就出错了,为何
const TInt KNumberOfIcons_1(1);
TBool CDynamicListContainer::AddOneItem(TText* szText, int inIconName, int aBitmapId, int aMaskId)
{
if (iSavedGamesListBox != NULL)
{
CTextListBoxModel* model = iSavedGamesListBox->Model(); // not taking ownership
CDesCArray* savedGamesArray = STATIC_CAST(CDesCArray*, model->ItemTextArray());
TBuf<256> ibuf;
ibuf = (const TText* )szText;
savedGamesArray->AppendL(ibuf);
//icon
HBufC* iconFileName;
iconFileName = StringLoader::LoadLC(inIconName); // Pushes iconFileName onto the Cleanup Stack.
// Create an array of icons, reading them from the file
CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(KNumberOfIcons_1);
CleanupStack::PushL(icons);
icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, aBitmapId, aMaskId));
// icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmDynamiclist2player, EMbmDynamiclist2player_mask));
CleanupStack::Pop(icons);
CleanupStack::PopAndDestroy(iconFileName);
iSavedGamesListBox->ItemDrawer()->ColumnData()->SetIconArray(icons); // passing ownership of icons
iSavedGamesListBox->HandleItemAdditionL();
return TRUE;
}
return FALSE;
}