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 );
}
[/CODE]
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)
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(....);
[/CODE]
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(....);
[/CODE]
Note also that your code missed the "&" in the aFilePath parameter.
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
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.