我在网格中有一个RealEdit,我将自动声明设置为YES。
名称是myRealEdit,数据源是myTable,字段是myRealField。
在修改后的方法中,我想获取值,我需要做一个IF控制。
如果该值为0,则更改字段的值;如果该值不为0,则将抛出输入的值并恢复先前的值。
我在修改后的方法中使用了这段代码:
public boolean modified()
{
boolean ret;
real storedValue;
ret = super();
storedValue = myTable.myRealField; // there is another way to get the value ?
if (myRealEdit.valueStr() == "0")
//accept the value
if (!myRealEdit.valueStr() != "0")
{
myRealEdit.realValue(storedValue);
}
return ret;
}
如果该值不为0(零),请不要恢复之前的值。
我必须使用另一种方法?还有另一种获取真实价值的方法吗?
感谢您的建议,
请享用!!
由于您modified
在答案中使用的是方法,因此我想您要将此字段验证放在控件级别(而不是数据源或表级别)上。
正如@Jan B. Kjeldsen在他的评论中建议的那样,您应该使用该validate
方法进行验证。modified
仅当您要添加除字段值修改之外还要执行的某些逻辑时,才使用该方法。
该validate
方法可能类似于
public boolean validate()
{
return this.realValue() == 0 && super() || checkFailed(strFmt("Value %1 is not permitted", this.realValue()));
// TODO please replace this with a Label and explain to the user why the value is not permitted and what he or she can do to resolve this
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句