I followed an example from Delphi Basic. I copied it and able to run it well in my Delphi 2007.
So I build my own program and used this method as mentioned above but run into error. The error stated "...raised exception class EConvertError with message "9.702827253E+003' is not a valid floating point value".
Scratching my head.....
var
readResult2:WideString;
strSN:String;
strSN2:String;
floatSN:Extended;
when readResult2
is read as '+9.702827253E+003'#$A as indicated in the watch,
strSN := readResult2;
Delete(strSN,1,1);
floatSN := StrToFloat(strSN); //This line created an error
freqSformat.Text := FloatToStr(floatSN);
Any idea why it happened? I am still stumped...
The problem is the trailing #$A
character. I can't see where your text is coming from, but you need to remove that stray character.
StrToFloat('+9.702827253E+003'); // succeeds
StrToFloat('+9.702827253E+003'#$A); // raise EConvertError
A call to Trim
would remove it.
StrToFloat(Trim('+9.702827253E+003'#$A)); // succeeds
But you'd surely be better off removing it properly. In order to know how to do that, you'd need to know where it came from in the first place. We don't know that. You do.