Reputation: 1581
I have in a Grid a RealEdit , I set the autodeclaration YES.
The name is myRealEdit , DataSource is myTable and the Field is myRealField.
In the modified method I want to get the value, I need to do a IF control.
IF the value is 0 change the Filed's value IF the value is not 0 throws the value entered and restores the previous value.
I used this code, in modified method:
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;
}
If the value is not 0 (zero) don't restore the previous value.
I have to use another method ? There is another way to get the real value ?
Thanks in advice,
enjoy!!
Upvotes: 1
Views: 8353
Reputation: 5107
Since you are using the modified
method in your answer, I suppose you want to put this field validation on the control level (instead of the datasource or table level).
As @Jan B. Kjeldsen suggested in his comment, you should use the validate
method to do this validation. Use the modified
method only if you want to add some logic that is executed in addition to the field value modification.
The validate
method could look similar to
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
}
Upvotes: 2
Reputation: 1581
I find a possible way,
I used this code:
public boolean modified()
{
boolean ret;
if (myRealEdit.valueStr() == "0")
{
//accept the value
ret = super();
}
if (!myRealEdit.valueStr() != "0")
{
info("Value not permit");
// nothing to do
}
return ret;
}
In this way, if and only if I have a value 0 I modified the value.
I need to get or read the Real value just inserted from myRealEdit in the modified method.
If the community has comments or improvements inserted, will be more information.
Upvotes: 0