HBufC 的 zero 方法测试
今天看到 HBufC 的Zero 方法了,帮助中说是
Zero()
IMPORT_C void Zero();
Sets the length of the data to zero.
把 Lenght 设为 0 了,那内容还存不存在,下面是试验代码
HBufC* aTest = HBufC::NewL(12);
CleanupStack::PushL(aTest); _LIT(KTest,"qijianzhou"); TPtr ptr = aTest->Des(); TBuf<12> aBuf(KTest); ptr.Append(aBuf);
_LIT(KFormat1,"length=%d\nsize=%d\ncontent=%S");
console->Printf(KFormat1,aTest->Length(),aTest->Size(),&ptr);
console->Getch(); ptr.Zero(); console->Printf(KFormat1,aTest->Length(),aTest->Size(),&ptr);
CleanupStack::PopAndDestroy();
|
_LIT(KFormat1,"length=%d\nsize=%d\ncontent=%S");
HBufC* aTest = HBufC::NewL(12); CleanupStack::PushL(aTest); _LIT(KTest,"qijianzhou"); TPtr ptr = aTest->Des(); TBuf<12> aBuf(KTest); // 测试刚创建完后长度及大小 console->Printf(KFormat1,aTest->Length(),aTest->Size(),&ptr); console->Getch();
ptr.Append(aBuf);
console->Printf(KFormat1,aTest->Length(),aTest->Size(),&ptr);
console->Getch(); ptr.Zero(); console->Printf(KFormat1,aTest->Length(),aTest->Size(),&ptr);
CleanupStack::PopAndDestroy();
|
经测试,刚创建后的 Length 及 Size 都为 0,内容为空
如果对于 HBufC 及 TBuf ,赋值时,内容长度大于指定的长度,则程序会出现异常
安平2009@原创
[email protected]