×

Discussion Board

Results 1 to 4 of 4

Hybrid View

  1. #1
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    290

    Function parameter const TdesC& aAMRFilename fill with data?

    Hi,

    my problem is illustrated by the following code...

    Code:
    void CServerSettings::CreateAMRFileNameL(const TDesC aFilePath, const TDesC& aAMRFilename )
    	{
    	
    	TInt64 currentTimeMillis = (static_cast<CTMSAppUi*>( iEikonEnv->EikAppUi() ) )->iDatabaseEngine->GetCurrentTimeMillis();
    	
    	TBuf<255> caption( NULL );
    	TBuf<255> caption2( NULL );
    	HBufC* buffer = HBufC::NewLC( 255 );
    	HBufC* result = HBufC::NewLC( 255 );
    
    	_LIT( KFormat, "%Ld" );
    	_LIT( KFileExtension, ".amr" );		
    
    
    	caption.Append( aFilePath );
    	caption.Append( KFormat );
            caption.Append( KFileExtension );
    	
    	
    	caption2.Format( caption, currentTimeMillis );
    	buffer->Des().Append( aFilePath );
    	buffer->Des().Append( KFormat() );
            buffer->Des().Append( KFileExtension() );
    	
    	result->Des().Format( *buffer, currentTimeMillis );
    	
    	
    	CleanupStack::PopAndDestroy( buffer );
    	
    	aAMRFilename = &caption2;
    	
    	CleanupStack::PopAndDestroy( result );
    	}

    I want to put a filepath like "C:\\Data\\" to my method
    inside my method i want to append "%Ld" (my format) then format my buffer with filename + extension.
    And then put the result back to aAMRFilename. How do i do this?


    Greetz
    Franky


    (These TDesC, HBufC*, TPtr stuff drives me mad)

  2. #2
    Regular Contributor
    Join Date
    Apr 2008
    Posts
    146

    Re: Function parameter const TdesC& aAMRFilename fill with data?

    const TDesC & means that the parameter is a constant parameter and the descriptor is constant too. If you really want to modify the parameter, do either:

    Code:
    void CServerSettings::CreateAMRFileNameL(const TDesC & aFilePath, TDesC & aAMRFilename )
    	{
    ...
    	TPtr ptr(aAMRFilename.Des());
            ptr = KMyConstantDescriptor;
            ptr.Append(KMoreText);
            ptr.Format(....);
    So now the descriptor is constant, the parameter not. But you can now modify the value using Des().

    Or, even easier, use the abstract modifiable descriptor type:

    Code:
    void CServerSettings::CreateAMRFileNameL(const TDesC & aFilePath, TDes & aAMRFilename )
    	{
    ...
            aAMRFilename = KMyConstantDescriptor;
            aAMRFilename.Append(KMoreText);
            aAMRFilename.Format(....);
    Note also that your code missed the "&" in the aFilePath parameter.

  3. #3
    Regular Contributor
    Join Date
    Sep 2008
    Posts
    290

    Re: Function parameter const TdesC& aAMRFilename fill with data?

    Hey,


    thanks, yes this is right. Now i am able to get this done. Thanks a lot!


    Greetz
    Franky

  4. #4
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: Function parameter const TdesC& aAMRFilename fill with data?

    No disrespect but maybe you should read a C++ book, you've been coming on the board for a while now, and const is a fundamental keyword in both C and C++ whose meaning is independant of Symbian C++.


    ANd you should review this, there is a bug in the header definition, as has been pointed out:
    void CServerSettings::CreateAMRFileNameL(const TDesC aFilePath, const TDesC& aAMRFilename )


    And this is not correct:

    void CServerSettings::CreateAMRFileNameL(const TDesC & aFilePath, TDesC & aAMRFilename )



    Constant descriptors should be:
    const TDesC&

    non constant descriptors should be:
    TDes&


    As shown in the last example, the first should not be applied.

    Not const TDes&
    Not TDesC&
    etc.

Similar Threads

  1. Undefined symbol - Compiling HelloWorld
    By synackSA in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 6
    Last Post: 2009-04-08, 11:02
  2. Need one HTTP client example
    By vinayakak in forum Symbian Networking & Messaging (Closed)
    Replies: 15
    Last Post: 2008-01-06, 06:44
  3. How to port Symbian OS String Descriptors
    By birol.sekerci in forum Symbian
    Replies: 17
    Last Post: 2007-11-08, 16:24
  4. RThread - parameter to the thread function
    By EduardFrank in forum Symbian
    Replies: 2
    Last Post: 2002-10-24, 06:11

Posting Permissions

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