当前位置: 代码迷 >> PB >> 关于settext()的困惑
  详细解决方案

关于settext()的困惑

热度:56   发布时间:2016-04-29 10:02:58.0
求教:关于settext()的困惑
itemchanged 事件内有如下语句

dw_1.accepttext()
dw_1.settext(trim(dw_1.gettext()))

目的:检查当前输入的内容是否包括空格,如果有则去掉
但为什么以上语句执行后没有效果呢 例如我输入“ 111” 焦点转以后并没有变成我想要的“111”
很是困惑,请高人指点

------解决方案--------------------
你自己到PB的帮助界面中看看即可知道如何处理了。在help的索引中输入settesx即可,看其中的代码例子。
我给你贴过来:
This example converts a number that the user enters in the column called credit to a negative value and sets both the item and the edit control's text to the negative number. This code is the script for the ItemChanged event. The data argument holds the newly entered value:

integer negative

IF dwo.Name = "credit" THEN

IF Integer(data) > 0 THEN

// Convert to negative if it's positive

negative = Integer(data) * -1

// Change the primary buffer value.

This.SetItem(row, "credit", negative)

// Change the value in the edit control

This.SetText(String(negative))

RETURN 1

END IF

END IF
------解决方案--------------------
在itemchanged事件里一般是用getitemXXX()和setitem()函数
------解决方案--------------------
应用itemchanged的参数data
在用setitem来做试试

探讨
itemchanged 事件内有如下语句

dw_1.accepttext()
dw_1.settext(trim(dw_1.gettext()))

目的:检查当前输入的内容是否包括空格,如果有则去掉
但为什么以上语句执行后没有效果呢 例如我输入“  111”  焦点转以后并没有变成我想要的“111”
很是困惑,请高人指点

------解决方案--------------------
在itemchanged里面,gettext取的还是上次获焦前的字符,要切换到其他地方才会改变,在itemchanged里面用accpettext不是一个太好的办法
听楼上的,用data试试
this.settext(trim(data)) 
如果还不行就换成setitem,区别在于settext可以不理会数据类型,而setitem的话非字符型还要做转换