views:

171

answers:

2

Hi,

Once again I am struggeling with Symbians Descriptors...

char fileName[128] = "somethingsomething";

Next I have then en TEntry object which has a member iName. To this iName I would like to assign my fileName. I tried to do it as follows:

TEntry anEntry;

anEntry.iName.Copy((TText8* )rEntity->fileName);

-

no instance of overloaded function " TBufC::Copy [with S=256]" matches the argument list
        argument types are: (TText8 *)
        object type is: TBufC<256>
                    anEntry.iName.Copy((TText8* )rEntity->fileName);

Do I need to use another function to copy the filename into entry.iname?

Many thanks

A: 

Wrap the zero-terminated const char [] data in a TPtrC to make it a descriptor that can be passed to Copy. However, TEntry::iName is a constant TBufC but you can call Des on it to get a modifiable TPtr:

anEntry.iName.Des().Copy(TPtrC8((TText8 *)rEntity->fileName));
laalto
Thanks for your answer but the problem remains the same... Is it possible that this iName member has no Copy method although its from type TBufC as the description outlines: TBufC< KMaxFileName > iName; The name of the file relative to the owning directory, with a maximum of KMaxFileName characters.
anEntry.iName = _L("Test"); This here works... drives me mad the descriptors. Is there maybe something like a strcpy in Symbian without using the stdlib?
Yes.. Something like `strcpy` is `TDes::Copy`. I've updated my answer to cater for the fact that TEntry::iName is a const `TBufC`.
laalto
+1  A: 

TBufC is non-modifiable (C is for "constant"). It doesn't have any Copy functions.

http://developer.symbian.com/main/documentation/sdl/symbian94/sdk/doc_source/reference/reference-cpp/E32_EKA2/TBufCClass.html

Try something like:

iName.Des().Copy(TPtrC8((TText8*)fileName));

or

TBuf<256> tmp;  // or HBuf if you're worried about using so much stack
tmp.Copy(TPtrC8((TText8*)filename));
iName = tmp;

If you can't change the type of iName, maybe you can change fileName to be stored in a descriptor instead of just a char array? As you've discovered, mixing the two is painful.

This all assumes that your 8-bit char is ascii or ISO-latin, not UTF-8. If the latter, you need to convert the character encoding as well.

Steve Jessop
Alright, that makes sense. However, the problem is that I am trying to implement some interface, so I am NOT able to change the type of the iName data member. Is there any way I can somehow assign the filename with casting to constant maybe :P
You can use operator= on TBufC. I'm a bit rusty, but try something like iName = TPtrC8(fileName). Note that you can instead call Des() on a TBufC to get a modifiable descriptor, which you can then call Copy on.
Steve Jessop
Thanks for this onebyone. iName = TPtrC8(fileName) does unfortunately not work. However, I should say that fileName is not a constant char as it changes during program execution. Hope that is not a problem I can still assign it somehow to this TBufC variable!