
Originally Posted by
wizard_hu_
HBufC is implicitly a HBufC16, and its Des method creates a TPtr16 object. So that TPtr8 is just strange in the error message.
Anyway
- setting lists work in an asynchronous, event-driven way, so passing references to local variables will not work. Whatever you pass to the setting items for modification, should be a member variable of yours
- while the use of dynamic buffers are advised in general, for user interaction (dialogs, forms, setting lists) they have no benefit
Consider trying with a simple TBuf<100> member variable.
EDIT: the HBufC=HBufC16 thing also applies to the others, like TBuf is a TBuf16, etc.
TBuf works fine, but I will try to use TDesC16 later, because my case have to use TDesC16.
Before that, I found a problem have to solve first, see below.
Below code works, when User clicking the menu item, it can generate a dynamical "Setting Name" item successfully.
Code:
/**
* Handle the selected event.
* @param aCommand the command id invoked
* @return ETrue if the command was handled, EFalse if not
*/
TBool CTestAppContainerView::HandleTestMenuItemSelectedL(TInt aCommand)
{
iTestAppContainer->SwitchControlView(CTestAppContainer::ESettingItemList);
TInt order = 0;
// Get the icon array if you want to set icons
CArrayPtr<CGulIcon>
* icons =
iTestAppContainer->SettingItemList()-> ListBox()->ItemDrawer()->FormattedCellData()->IconArray();
// Used for setting text items in enumerated controls
CArrayPtr<CAknEnumeratedText>* texts;
// Text input items
CAknTextSettingItem *textitem;
// Enumerated text items
CAknEnumeratedTextPopupSettingItem *enumitem;
// The setting item array
CAknSettingItemArray* items;
// Get the setting item array from the derived control
items = iTestAppContainer->SettingItemList()->SettingItemArray();
// Add your controls here to the item array
items->RecalculateVisibleIndicesL();
iTestAppContainer->SettingItemList()->HandleChangeInItemArrayOrVisibilityL();
// Make sure the order numbers are updated
order++;
//HBufC* buf = HBufC::NewL(_L("StringValue").Length());
//buf->Des().Append(_L("StringValue"));
TBuf<100> textvalue;
textvalue.Copy(_L("StringValue"));
textitem = new (ELeave) CAknTextSettingItem(order, textvalue);
textitem->SetEmptyItemTextL(KEmptyItemText);
// If you want to allow setting an empty string, uncomment this
// text->SetSettingPageFlags(CAknTextSettingPage::EZeroLengthAllowed);
textitem->ConstructL(
iTestAppContainer->SettingItemList()->IsNumberedStyle(), order,
_L("Setting Name"), icons, R_TEXT_SETTING_PAGE, -1);
items->AppendL(textitem);
return ETrue;
}
But when I add the other part to that code, when User clicking the menu item , the whole application exit with a panic code "Setting Item Lis 6".
Code:
/**
* Handle the selected event.
* @param aCommand the command id invoked
* @return ETrue if the command was handled, EFalse if not
*/
TBool CTestAppContainerView::HandleTestMenuItemSelectedL(TInt aCommand)
{
iTestAppContainer->SwitchControlView(CTestAppContainer::ESettingItemList);
TInt order = 0;
// Get the icon array if you want to set icons
CArrayPtr<CGulIcon>
* icons =
iTestAppContainer->SettingItemList()-> ListBox()->ItemDrawer()->FormattedCellData()->IconArray();
// Used for setting text items in enumerated controls
CArrayPtr<CAknEnumeratedText>* texts;
// Text input items
CAknTextSettingItem *textitem;
// Enumerated text items
CAknEnumeratedTextPopupSettingItem *enumitem;
// The setting item array
CAknSettingItemArray* items;
// Get the setting item array from the derived control
items = iTestAppContainer->SettingItemList()->SettingItemArray();
// Add your controls here to the item array
items->RecalculateVisibleIndicesL();
iTestAppContainer->SettingItemList()->HandleChangeInItemArrayOrVisibilityL();
// Make sure the order numbers are updated
order++;
//HBufC* buf = HBufC::NewL(_L("StringValue").Length());
//buf->Des().Append(_L("StringValue"));
TBuf<100> textvalue;
textvalue.Copy(_L("StringValue"));
textitem = new (ELeave) CAknTextSettingItem(order, textvalue);
textitem->SetEmptyItemTextL(KEmptyItemText);
// If you want to allow setting an empty string, uncomment this
// text->SetSettingPageFlags(CAknTextSettingPage::EZeroLengthAllowed);
textitem->ConstructL(
iTestAppContainer->SettingItemList()->IsNumberedStyle(), order,
_L("Setting Name"), icons, R_TEXT_SETTING_PAGE, -1);
items->AppendL(textitem);
// Make sure the order numbers are updated
order++;
// Hold the value for the item in temp variable and set it to zero
TInt tmpvalue = 2;
TInt itemvalue = 0;
enumitem
= new (ELeave) CAknEnumeratedTextPopupSettingItem(order, itemvalue);
enumitem->ConstructL(
iTestAppContainer->SettingItemList()->IsNumberedStyle(), order,
_L("Enum item"), icons, R_ENUMERATED_SETTING_PAGE, -1, 0,
R_POPUP_SETTING_TEXTS);
// Get the value array
texts = enumitem->EnumeratedTextArray();
// Empty it
//texts->ResetAndDestroy();
texts->Reset();
texts->AppendL(new CAknEnumeratedText(0, _L("first (0)").AllocL()));
texts->AppendL(new CAknEnumeratedText(1, _L("second (1)").AllocL()));
texts->AppendL(new CAknEnumeratedText(10, _L("third (10)").AllocL()));
// Set the real value for the item
itemvalue = tmpvalue;
// Tell the control to load the value in
enumitem->LoadL();
items->AppendL(enumitem);
return ETrue;
}
Below is the resource definition in the "TestAppContainer.rssi" file :
Code:
RESOURCE AVKON_SETTING_ITEM_LIST r_settings_list
{
title = "Settings";
}
RESOURCE AVKON_SETTING_PAGE r_text_setting_page
{
type = EEikCtEdwin;
editor_resource_id = r_text_edwin;
}
RESOURCE EDWIN r_text_edwin
{
width = 20;
lines = 1;
maxlength = 64;
default_input_mode=EAknEditorTextInputMode;
allowed_input_modes=EAknEditorTextInputMode;
}
RESOURCE AVKON_SETTING_PAGE r_enumerated_setting_page
{
type = EAknCtPopupSettingList;
editor_resource_id = r_popup_setting_list;
}
RESOURCE POPUP_SETTING_LIST r_popup_setting_list
{
flags = 0;
}
RESOURCE AVKON_POPUP_SETTING_TEXTS r_popup_setting_texts
{
setting_texts_resource = r_texts;
}
RESOURCE ARRAY r_texts
{
items =
{
AVKON_ENUMERATED_TEXT { value=0; text = "dummy";}
};
}
Please help me to find out what problem it is !