Sunday, June 12, 2005

25. What do Length(), MaxLength(), SetLength() and SetMax() do?

TDesC::Length() returns the number of characters the descriptor contains.

[While we're on the subject of descriptor length, beware! Be careful not to confuse Size() and Length(). They do similar things, but while Length() returns the number of characters the descriptor contains, Size() returns the number of bytes it occupies. For 8-bit descriptors, where each character occupies a byte, this is the same thing. However, on all releases of Symbian OS since v5u, the native character width has been 16 bits, so each character occupies two bytes. Unless you're working with a very old SDK, you'll find that Size() always returns a value which is double that of Length()].

TDes::MaxLength() returns the maximum length allowed for a modifiable descriptor.

TDes::SetLength() can be used to change the descriptor's length to any value between zero and its maximum length. You can also use TDes::Zero() to set the length to zero. And TDes::SetMax() to set the length to the maximum.

[SetMax() has a slightly misleading name. It doesn’t allow you to change the maximum length of the descriptor, which would, in effect, allow you to resize its data area].

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

Google
WWW Descriptors FAQ