3
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by deyken
0

Many, basically trying to do something not matematically possible: Divide by cero, log of a negative number, sqrt of a negative number... and also operations with a result out of the limits: a:= Power(999,999) for instance won't fit in your PC!

0

Hi There,

This issue usually occurs when you attempt to convert a null string to a floating point, for instance:

[var
\ MyFloat : Double; {or extended if you want}

procedure Button1OnClick(Sender : TObject);
begin
MyFloat := StrToFloat(Edit1.Text); {<== Error occurs here when Edit1.Text is empty}
end;

]

To fix this problem is easy. Simply use the alternative type casting function StrToFloatDef(String Value, Default Float). So:

[var
\ MyFloat : Double; {or extended if you want}

procedure Button1OnClick(Sender : TObject);
begin
MyFloat := StrToFloatDef(Edit1.Text, 15.28); {<== Error occurs here when Edit1.Text is empty}
end;

]

HOPE THAT HELPS!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.