×

Discussion Board

Results 1 to 14 of 14
  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    39

    Red face How to new a TDes object ?

    Hi,

    IMPORT_C CAknTextSettingItem( TInt aIdentifier, TDes& aText );

    How to new a TDes object ?

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: How to new a TDes object ?

    You would not, if you need dynamic buffers handlings you would generally use HBufC, and with static ones you could use the T-Classes such as TBuf, anyway, what is the use case and the actual problem ?

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    39

    Re: How to new a TDes object ?

    Quote Originally Posted by symbianyucca View Post
    You would not, if you need dynamic buffers handlings you would generally use HBufC, and with static ones you could use the T-Classes such as TBuf, anyway, what is the use case and the actual problem ?
    I found it here :


    http://www.developer.nokia.com/Commu...ated_Text_Item

    Code:
    // Make sure the order numbers are updated
    	order++;
    	textitem = new (ELeave)CAknTextSettingItem(order, textvalue);
    	textitem->SetEmptyItemTextL(KEmptyItemText);
    But I don't know how to construct the "textvalue" object!!

  4. #4
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: How to new a TDes object ?

    Basically you could use HBufC and then use its Des() to get TPtr pointer out and use it, or simply have a class member TBuf variable and use it. Note that if you use HBufC, you do need to remember to delete it after you have dismissed the CAknTextSettingItem, and not before, thus you might be safer on using the TBuf type variable which would be member variable for the container where you are using the CAknTextSettingItem.

  5. #5
    Registered User
    Join Date
    Sep 2011
    Posts
    203

    Re: How to new a TDes object ?

    I guess you are trying to pass value to CAknTextSettingItem(order, textvalue).

    TBuf<100> textvalue;
    textvalue.Copy(_L("abcd"));
    or
    you can use literal also
    _LIT(textvalue,"sdf");

  6. #6
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: How to new a TDes object ?

    Quote Originally Posted by please_help View Post
    ...
    you can use literal also
    _LIT(textvalue,"sdf");
    No you can not, see the SDK API docs, it says as CAknTextSettingItem (TInt aIdentifier, TDes &aText) and as it is TDes , you do need to pass non-constant variable in there.

  7. #7
    Registered User
    Join Date
    Sep 2011
    Posts
    203

    Re: How to new a TDes object ?

    ok thanks for correcting me

  8. #8
    Registered User
    Join Date
    Apr 2012
    Posts
    39

    Re: How to new a TDes object ?

    Quote Originally Posted by symbianyucca View Post
    Basically you could use HBufC and then use its Des() to get TPtr pointer out and use it, or simply have a class member TBuf variable and use it. Note that if you use HBufC, you do need to remember to delete it after you have dismissed the CAknTextSettingItem, and not before, thus you might be safer on using the TBuf type variable which would be member variable for the container where you are using the CAknTextSettingItem.
    Please help, I still can't solve it:

    Code:
    	HBufC* buf = HBufC::NewL(_L("StringValue").Length());
    	buf->Des().Append(_L("StringValue"));
    	
    	textitem = new (ELeave) CAknTextSettingItem(order, buf->Des());
    	textitem->SetEmptyItemTextL(KEmptyItemText);
    It says "no matching function for call to `CAknTextSettingItem::CAknTextSettingItem(TInt&, TPtr8)'"

  9. #9
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: How to new a TDes object ?

    firstly, I did not tell you to use Des() directly. You do need to use TPtr pointer variable there, since the Des() would not give modifiable descriptor directly. Also you can not use HBufC in a way that you would not save the pointer, otherwise you end up leaking memory.

    Also, how would you think you are going to get the value out from the item if you are not saving it ? I would suggest that you simply use TBuf variable which is member of the container..

  10. #10
    Registered User
    Join Date
    Apr 2012
    Posts
    39

    Re: How to new a TDes object ?

    Quote Originally Posted by symbianyucca View Post
    firstly, I did not tell you to use Des() directly. You do need to use TPtr pointer variable there, since the Des() would not give modifiable descriptor directly. Also you can not use HBufC in a way that you would not save the pointer, otherwise you end up leaking memory.

    Also, how would you think you are going to get the value out from the item if you are not saving it ? I would suggest that you simply use TBuf variable which is member of the container..
    But by using TBuf, I can not set text from a TDesC16 variable ???

    I want to create all CAknSettingItem dynamically, so all text value are from variables .

    Please help .

  11. #11
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,750

    Re: How to new a TDes object ?

    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.

  12. #12
    Registered User
    Join Date
    Apr 2012
    Posts
    39

    Re: How to new a TDes object ?

    Quote Originally Posted by wizard_hu_ View Post
    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 !

  13. #13
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,750

    Re: How to new a TDes object ?

    Quote Originally Posted by fnnokia View Post
    TBuf works fine, but I will try to use TDesC16 later, because my case have to use TDesC16.

    ...

    Please help me to find out what problem it is !
    The TDesC requirement. It just can not work, in fact it can not even be. Setting items work in the way that you pass your own variable to them in their descriptor, then it is going to be used as default content. However it is also the variable which will get the result:
    Quote Originally Posted by SDK Help
    void CAknSettingItem::StoreL() [virtual]

    This command externalizes the current setting.

    The displayed (internal) copy is transferred to the external copy (the one referenced in the constructor).

    This must be called by the client if he wants this to happen. Note that StoreAllL() on the setting item list will call this for each setting item.
    So experimenting with constant types is not a good idea.

  14. #14
    Registered User
    Join Date
    Apr 2012
    Posts
    39

    Re: How to new a TDes object ?

    Quote Originally Posted by wizard_hu_ View Post
    The TDesC requirement. It just can not work, in fact it can not even be. Setting items work in the way that you pass your own variable to them in their descriptor, then it is going to be used as default content. However it is also the variable which will get the result:So experimenting with constant types is not a good idea.
    Thanks. Now problems are solved.

Similar Threads

  1. TCalTime to TDes
    By mastermindcoders in forum Symbian
    Replies: 1
    Last Post: 2009-10-16, 22:30
  2. TInteger to TDes?
    By strike_noir in forum Symbian
    Replies: 15
    Last Post: 2009-03-20, 06:57
  3. TBuf<256> to TDes?
    By VinodRaut in forum Symbian
    Replies: 14
    Last Post: 2007-05-31, 10:47
  4. Right value for inizializing TDes...
    By BigBozMan in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2003-06-25, 04:03
  5. Right value for inizializing TDes...
    By BigBozMan in forum Symbian User Interface
    Replies: 1
    Last Post: 2003-06-24, 12:41

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×