How to use the modifiable pointer descriptor — TPtr
来源:互联网 发布:aop编程作用 编辑:程序博客网 时间:2024/06/06 00:31
下面的内容摘自Symbian S60 3rd Edition SDK,先把英文原版贴在这里,等时间充足的时候我再把它翻译出来。How to use the modifiable pointer descriptor — TPtr《如何使用可修改的指针描述符TPtr》
How to use the modifiable pointer descriptor — TPtr
Modifiable pointer descriptors are useful for referencing strings or data which can be accessed and changed.
-
For text data, it is usual to construct a
TPtr
type and allow the appropriate variant, either aTPtr
or aTPtrC
to be selected at build time. -
For binary data, an explicit
TPtr8
is used. -
It is rare to use an explicit
TPtr16
.
Constructing a TPtr
A modifiable pointer descriptor can be constructed in a number of ways:
-
another modifiable pointer descriptor.
-
from a non-modifiable buffer descriptor using the
Des()
function -
from an explicit pointer into memory and specifying a maximum length.
-
from an explicit pointer into memory and specifying the length of the data and a maximum length.
The following code fragment constructs a TPtr
to represent the data already represented by another TPtr
:
TPtr ptr1;
...
TPtr ptr2(ptr1);
...
The following code fragment constructs a TPtr
for a non-modifiable buffer descriptor, a TBufC<TInt>
, using the Des()
function. Data that would normally be unmodifiable through the TBufC<TInt>
can be changed through the TPtr
.
The source are literals which are converted to descriptor type.
_LIT(KText,"Hello World!");
_LIT(KExtraText," & Hi");
...
TBufC<16> buf1(KText);
...
TPtr ptr = buf1.Des();
...
ptr.Delete((ptr.Length()-1),1);
ptr.Append(KExtraText);
Define a TText
area initialised to contain the string "Have a nice day":
The following code fragments show the construction of a TPtr
using a pointer and specifying a length and a maximum length. This technique is not commonly used. Literals are a much better way of defining string constants.
TText str[16] = {'H', 'a', 'v', 'e', ' ', 'a',
' ', 'n', 'i', 'c', 'e',
' ', 'd', 'a', 'y', '/0'};
TPtr ptr(&str[0],15,16);
The descriptor ptr
represents the data in str
and is constructed to have a current length of 15 (the length of the text, excluding the zero terminator) and a maximum length of 16 (the actual length of str
). Once the descriptor has been constructed, it has no further use for the zero terminator.
TPtr ptr(&str[0],15,16);
Replacing data through the TPtr
Data can be completely replaced using the assignment operator or the Copy() function.:
_LIT(KText,"Hi there");
...
ptr = KText;
...
ptr.Copy(KText);
Note the use of the _LIT
macro to define the source string. A literal is converted into a descriptor type.
The length of ptr
is now 8 but the maximum length remains unchanged. The size depends on the build variant. In a non-Unicode build, this is 8 but in a Unicode build, this becomes 16 (two bytes for every character).
Changing the length of data
The length of the data represented can be changed.
_LIT(KText,"Hi there");
...
ptr = KText;
ptr.SetLength(2);
ptr.Zero();
For example, after ptr.SetLength(2)
, the descriptor represents the string "Hi". The length can even be set to zero so that after ptr.Zero()
, the descriptor represents no data. Nevertheless, the maximum length remains unchanged.
- How to use the modifiable pointer descriptor — TPtr
- How to use the non-modifiable pointer descriptor — TPtrC
- How to use the non-modifiable buffer descriptor — TBufC
- How to use modifiable buffer descriptor — TBuf
- How to use the heap descriptor — HBufC
- How to use the pointer of function in a class?
- The reason to use void pointer
- How to use the CAknWaitDialog
- how to use the CAknwaitDialog
- How to use the CAknWaitDialog
- How to use the BAPI_BUPA_ADDRESS_CHANGE
- How to use the HttpWebRequest object
- How To Use the C Run-Time
- How to Use the Visual C++ DEBUGGER
- How to Create and Use the DLL
- How to use the RTC driver
- How to use the CONVERSION_EXIT_PARVW_INPUT and CONVERSION_EXIT_PARVW_OUTPUT
- the examples :how to use LP_SOLVE.EXE
- 翻译:Single Sign-On for Everyone
- How to use the non-modifiable pointer descriptor — TPtrC
- Can not open file with "ios_base::in | ios_base::app"
- 数据库域的动态插入
- 怎样在我最大化窗口时全屏显示(就是将“开始”任务兰一起填充)(就象进入游戏时的全屏效果一样,进入屏保时也是)
- How to use the modifiable pointer descriptor — TPtr
- 获得数据库中表,字段的详细信息
- b/s开发常用javaScript技术
- 进程间传递消息(发送和接收系统消息)
- 移动定位业务
- asp.net控件开发基础(1)
- 使用.NET实现断点续传
- GridView模版列嵌套GirdView显示主从表数据
- JavaScript:网站页面js请慎用onload事件