Home » U++ Library support » LineEdit, EditFields, DocEdit » Is there a way to make EditDouble return 0 if it has no value?
Re: Is there a way to make EditDouble return 0 if it has no value? [message #27598 is a reply to message #27596] |
Sun, 25 July 2010 13:01 |
|
MatthiasG wrote on Sun, 25 July 2010 10:13 | Hello,
as written in the topic, is there a way to let EditDouble return 0.0 for a field without a value in it? e.g. if i have two EditDouble fields d1 and d2, with d1 containing 1.0 and d2 has empty value, i want double d = d1 + d2 to return 1.0...
greetings,
Matthias
|
Hi Matthias,
I usually solve this by prohibiting empty field: editfield.NotNull(true), also can be set in layout designer. But sometimes this solution might annoy user.
Another option is to check before using the value, just adding something like d1=IsNull(d1)?0:d1 in you code should be enough.
I'm not aware of any way how to do this directly with current EditDouble, but you can easily define your own control. Actually, you only have to create you own converter and since you can inherit most of it from the original ConvertDouble, it is really simple. All the code you need is class MyConvertDouble:public ConvertDouble{
public:
Value Scan(const Value& text) const {
Value v = UPP::Scan(DOUBLE_V, text);
if(IsError(v)) return v;
if(IsNull(v)) return notnull ? NotNullError() : Value(0); // <-- This is the important line
double m = v;
if(m >= minval && m <= maxval) return v;
return ErrorValue(UPP::Format(t_("Number must be between %g and %g."), minval, maxval));
}
};
typedef EditMinMax<double, MyConvertDouble> MyEditDouble;
Best regards,
Honza
|
|
|
Goto Forum:
Current Time: Sun Apr 28 22:38:07 CEST 2024
Total time taken to generate the page: 0.04340 seconds
|