Monday, May 09, 2005


Tip 6: Need to read from an HBufC? Don't call Des().

To read from a descriptor, you only need it to be non-modifiable, a TDesC. Class HBufC derives from TDesC, so it has access to all the non-modifiable functions implemented by TDesC. All you need to do is dereference the pointer.

_LIT(KBert, "Bert");
HBufC* bert = KBert.AllocL();

TPtrC halfOfBert = bert->Left(2);

One of the most common mistakes made when using descriptors is to call Des() on an HBufC* when you only need a constant descriptor.

_LIT(KBert, "Bert");
HBufC* bert = KBert().AllocL();

TPtrC halfOfBert = bert->Des().Left(2); // Unnecessary call to Des()

It won’t do any harm, but is totally unnecessary and wastes time, space and typing

This page is powered by Blogger. Isn't yours?

WWW Top Tips for Descriptors