Hello,
In :
TNxCustomNumberEdit.GetValue(), there is a StrToFloat() and I had problems if the user enters very large numbers (overflow exception).
I suggest you put a try-except around the StrToFloat().
What do you think ?
Regards
[TNxNumberEdit] Suggestion
Started by bertrod, May 30 2008 06:11 PM
7 replies to this topic
#1
Posted 30 May 2008 - 06:11 PM
#2
Posted 30 May 2008 - 08:11 PM
Hello Bertrod,
I am not sure that I understand, can you please tell me where you have locate this line (or send me one small example) and I will add it.
Best regards
I am not sure that I understand, can you please tell me where you have locate this line (or send me one small example) and I will add it.
Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#3
Posted 02 June 2008 - 11:20 AM
Hi,
There is also TryStrToFloat with built-in exception handling.
There is also TryStrToFloat with built-in exception handling.
QUOTE (bertrod @ May 30 2008, 07:11 PM) <{POST_SNAPBACK}>
Hello,
In :
TNxCustomNumberEdit.GetValue(), there is a StrToFloat() and I had problems if the user enters very large numbers (overflow exception).
I suggest you put a try-except around the StrToFloat().
What do you think ?
Regards
In :
TNxCustomNumberEdit.GetValue(), there is a StrToFloat() and I had problems if the user enters very large numbers (overflow exception).
I suggest you put a try-except around the StrToFloat().
What do you think ?
Regards
G.W. van der Vegt
#4
Posted 02 June 2008 - 12:05 PM
Here is my TNxCustomNumberEdit.GetValue function in NxEdit.pas with the StrToFloat :
Sorry if this line has already been corrected in a more recent version. As wvd_vegt says, using TryStrToFloat should be already enough.
Regards
CODE
function TNxCustomNumberEdit.GetValue: Double;
var
ValidText: string;
begin
if Text = '' then Result := 0 else
begin
ValidText := GetValidText(Text, eoAllowFloat in FOptions, eoAllowSigns in FOptions);
if ValidText = '' then ValidText := '0';
Result := StrToFloat(ValidText);
CheckBounds(Result);
end;
end;
var
ValidText: string;
begin
if Text = '' then Result := 0 else
begin
ValidText := GetValidText(Text, eoAllowFloat in FOptions, eoAllowSigns in FOptions);
if ValidText = '' then ValidText := '0';
Result := StrToFloat(ValidText);
CheckBounds(Result);
end;
end;
Sorry if this line has already been corrected in a more recent version. As wvd_vegt says, using TryStrToFloat should be already enough.
Regards
#5
Posted 02 June 2008 - 03:10 PM
Hello Bertrod,
Please try with next update:
Best regards
Please try with next update:
CODE
function TNxCustomNumberEdit.GetValue: Double;
var
ValidText: string;
begin
if Text = '' then Result := FMin else
begin
ValidText := GetValidText(Text, eoAllowFloat in FOptions, eoAllowSigns in FOptions);
if ValidText = '' then ValidText := FloatToStr(Min);
TryStrToFloat(ValidText, Result);
AdjustToRange(Result);
end;
end;
var
ValidText: string;
begin
if Text = '' then Result := FMin else
begin
ValidText := GetValidText(Text, eoAllowFloat in FOptions, eoAllowSigns in FOptions);
if ValidText = '' then ValidText := FloatToStr(Min);
TryStrToFloat(ValidText, Result);
AdjustToRange(Result);
end;
end;
Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#6
Posted 03 June 2008 - 02:41 PM
Hi Boki,
According to the help files, TryStrToFloat nothing is said about the value parameter if the function returns false.
Technically you should code something like:
According to the help files, TryStrToFloat nothing is said about the value parameter if the function returns false.
Technically you should code something like:
CODE
if TryStrToFloat(ValidText, Result) then
AdjustToRange(Result)
else
result:=Min; //or some other value, probably the old/previous value
AdjustToRange(Result)
else
result:=Min; //or some other value, probably the old/previous value
QUOTE (Boki (Berg) @ Jun 2 2008, 04:10 PM) <{POST_SNAPBACK}>
[code=auto:0]
ValidText := GetValidText(Text, eoAllowFloat in FOptions, eoAllowSigns in FOptions);
if ValidText = '' then ValidText := FloatToStr(Min);
TryStrToFloat(ValidText, Result);
AdjustToRange(Result);
ValidText := GetValidText(Text, eoAllowFloat in FOptions, eoAllowSigns in FOptions);
if ValidText = '' then ValidText := FloatToStr(Min);
TryStrToFloat(ValidText, Result);
AdjustToRange(Result);
G.W. van der Vegt
#7
Posted 03 June 2008 - 03:47 PM
Hello Wim,
Maybe this could be final code:
Previously declare FValue in private section and set
inside Create of TNxCustomNumberEdit
Best regards and thanks
Maybe this could be final code:
CODE
function TNxCustomNumberEdit.GetValue: Double;
var
ValidText: string;
begin
if Text = '' then Result := FMin else
begin
ValidText := GetValidText(Text, eoAllowFloat in FOptions, eoAllowSigns in FOptions);
if ValidText = '' then ValidText := FloatToStr(Min);
if TryStrToFloat(ValidText, Result) then
begin
AdjustToRange(Result);
FValue := Result;
end else Result := FValue;
end;
end;
var
ValidText: string;
begin
if Text = '' then Result := FMin else
begin
ValidText := GetValidText(Text, eoAllowFloat in FOptions, eoAllowSigns in FOptions);
if ValidText = '' then ValidText := FloatToStr(Min);
if TryStrToFloat(ValidText, Result) then
begin
AdjustToRange(Result);
FValue := Result;
end else Result := FValue;
end;
end;
Previously declare FValue in private section and set
CODE
FValue := 0;
inside Create of TNxCustomNumberEdit
Best regards and thanks
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#8
Posted 05 June 2008 - 10:56 AM
Hi Boki,
Looks ok to me.
Looks ok to me.
G.W. van der Vegt
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











