动态创建控件时碰到的问题

ari 2004-07-21 10:31:20
我在开发程序的过程中,碰到一个问题,希望能得到大家的指点:

///< 循环画出控件
for ( i = 0; i <= 14; i++,j++ ) {
pCtrl = CtlNewControl( (void**)&frmP, kindcode[i].flag, checkboxCtl,kindcode[i].name,
10, 25 + j * 15,
320, 28, stdFont, 0, true );
CtlDrawControl( pCtrl );
CtlSetValue( pCtrl, 1 );
}

此段代码为动态创建一组CheckBox,其中的kindecode的结构为:
kindcode {
UInt16 flag;
Char name[32];
};
在程序中为定义好的一个结构数组.
kindcode [] = {
{ 1, "A" },
{ 2, "B" },
{ 3, "C" },
...
};
程序代码能够按照我的设想来创建,但我发现当运行此段代码时,在Palm Emulator目录下面有log产生,内容为:
An "unallocated chunk of memory" is a chunk of memory that has not been reserved for use by the application

through calling MemPtrNew or MemHandleNew. It should not be accessed by applications under any circumstances.

Such an access usually means that an application is accessing a chunk that used to be allocated to the

application but has since been returned with MemPtrFree or MemHandleFree.
我不确定此log的含义,希望能得到各位的指点。

...全文
221 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
nowaytolive 2004-08-09
  • 打赏
  • 举报
回复
严重关注!!!
lxrlxr20021 2004-07-22
  • 打赏
  • 举报
回复
用dotdottwo设断点跟踪一下是哪里访问了非法内存
sinon 2004-07-22
  • 打赏
  • 举报
回复
这种错误的典型情况是写内存越界.

kindcode [] 有定义15项吗?
能保证pCtrl每次都创建成功吗?

其实你的问题,用CW来DEBUG应该很容易找出问题吧....
lxrlxr20021 2004-07-22
  • 打赏
  • 举报
回复
1.kindcode[i].flag是控件的id标识,在同一个form不能有重复,看与别的重复没有
2.textP对应kindcode[i].name,这里用kindcode[i].name是不对的,textP 是新建控件的label区,当控件销毁,系统自动释放,当Form的地址由于创建新控件而改变时,系统也自动释放,kindcode[i].name是一个全局变量,不能被系统自动释放,textP指向的内存可以自己指定自己分配。
3. pCtrl = CtlNewControl( (void**)frmPP, kindcode[i].flag, checkboxCtl,kindcode[i].name,
10, 25 + j * 15,
320, 28, stdFont, 0, true );

显示坐标,宽度越界,你的宽度时每一个控件320宽度,pda显示屏要多大,你限制边界不要超过160x160,我的机器可以上320*320,实际用的时候不能设为160以上,但可以以2倍的尺寸自动转换显示
lxrlxr20021 2004-07-22
  • 打赏
  • 举报
回复
CtlNewControl

--------------------------------------------------------------------------------

Prototype
ControlType *CtlNewControl (void **formPP,
UInt16 ID, ControlStyleType style,
const Char *textP, Coord x, Coord y, Coord width,
Coord height, FontID font, UInt8 group,
Boolean leftAnchor)

Parameters
<-> formPP Pointer to the pointer to the form in which the new control is installed. This value is not a handle; that is, the formPP value may change if the object moves in memory. In subsequent calls, always use the new formPP value returned by this function.
-> ID Symbolic ID of the control.
-> style A ControlStyleType value specifying the kind of control to create: button, push button, repeating button, check box, popup trigger, or popup selector. To create a graphical control or slider control dynamically, use CtlNewGraphicControl or CtlNewSliderControl, respectively.
-> textP Pointer to the control's label text. If textP is NULL, the control has no label. Only buttons, push buttons, and text boxes have text labels. Because the contents of this pointer are copied into their own buffer, you can free the textP pointer any time after the CtlNewControl function returns. The buffer into which this string is copied is freed automatically when you remove the control from the form or delete the form.
-> x Horizontal coordinate of the upper-left corner of the control's boundaries, relative to the window in which it appears.
-> y Vertical coordinate of the upper-left corner of the control's boundaries, relative to the window in which it appears.
-> width Width of the control, expressed in pixels. Valid values are 1-160. If the value of either of the width or height parameters is 0, the control is sized automatically as necessary to display the text passed as the value of the text parameter.
-> height Height of the control, expressed in pixels. Valid values are 1-160. If the value of either of the width or height parameters is 0, the control is sized automatically as necessary to display the text passed as the value of the text parameter.
-> font Font used to draw the control's label.
-> group Group ID of a push button or a check box that is part of an exclusive group. The control routines don't turn one control off automatically when another is selected. It's up to the application or a higher-level object, such as a dialog box, to manage this.
-> leftAnchor true specifies that the left bound of this control is fixed. This attribute is used by controls that resize dynamically in response to label text changes.
看看上面,你的函数参数有问题
ari 2004-07-21
  • 打赏
  • 举报
回复
没有人遇到过这个问题?
ari 2004-07-21
  • 打赏
  • 举报
回复
lxrlxr20021(艾文)
说的应该有道理,我看到
Manuals中提到:
<-> formPP Pointer to the pointer to the form in which the new control is installed. This value is not a handle; that is, the formPP value may change if the object moves in memory. In subsequent calls, always use the new formPP value returned by this function.
但我使用你的方法,还是出现log提示,正在研究中……

sbnth(金鳞岂非池中物,一遇风云便化龙)
kindcode是全局变量。问题应该不在这里。
sbnth 2004-07-21
  • 打赏
  • 举报
回复
指针问题,kingcode是全局的吗?
lxrlxr20021 2004-07-21
  • 打赏
  • 举报
回复
pCtrl = CtlNewControl( (void**)&frmP, kindcode[i].flag,
frmP有问题,创建新控件后,指向frmP地址有可能要变,&frmP还是原来的地址,
改为
FormPtr **frmPP;
*frmPP = &FrmP; //赋FrmP的初始内存地址,在创建新控件后,不能使用FrmP指向form,要用*frmPP指向表示新窗体的指针值

///< 循环画出控件
for ( i = 0; i <= 14; i++,j++ ) {
pCtrl = CtlNewControl( (void**)frmPP, kindcode[i].flag, checkboxCtl,kindcode[i].name,
10, 25 + j * 15,
320, 28, stdFont, 0, true );
CtlDrawControl( pCtrl );
CtlSetValue( pCtrl, 1 );
}

3,120

社区成员

发帖
与我相关
我的任务
社区描述
塞班系统(Symbian系统)是塞班公司为手机而设计的操作系统,它的前身是英国宝意昂公司的 EP ( Electronic Piece of cheese)操作系统。
社区管理员
  • Symbian社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧