### Forum

Forum
× CodeOcean Samples and DocFactory discussions and suggestions

# Question DMath example Mandel - StrToFloat raises exception

• Peter Heckert
• Topic Author
• Offline
• Junior Boarder
5 months 1 week ago - 5 months 1 week ago #13313 by Peter Heckert
Hi, the reason is this:

Dmath has its own "FloatStr" conversion routine that internaly uses the Pascal Str() function.
Str() does not use the global "Decimalseparator" setting, it apparently uses unconditionally "." as decimalseparator.

Here in germany we have "," as decimalseparator and because the program "Mandel" uses also the routine
FloatToStr different decimalseparators are intermixed and this causes the exception.

I believe it is the best to use "." as decimalseparator in this program unconditionally. This is common in scientific and technical software, because many other programs and measuring instruments - and DMath- use this unconditionally also.

These modifications in "mandelmw.pas" cure the problem for me:
procedure TForm1.FormActivate(Sender: TObject);
begin
{ Display center coordinates in exponential format
using function FloatStr from unit ustrings }

DefaultFormatSettings.DecimalSeparator:='.';      // add this line here

SetFormat(27, 17, True, False);
Edit2.Text := FloatStr(x0);
Edit3.Text := FloatStr(y0);
procedure TForm1.Button1Click(Sender: TObject);
var xDefaultFormatSettings : TFormatSettings;

{ Plots the Mandelbrot or Julia set }
var
Nx, Ny : Integer;
xt, yt : Float;
begin

xDefaultFormatSettings:=DefaultFormatSettings;     // ct9999
//  xDefaultFormatSettings.DecimalSeparator:=',';      //   remove this line    ct9999

if not SetFractal(StrToFloat(Edit1.Text,xDefaultFormatSettings),
StrToFloat(Edit8.Text,xDefaultFormatSettings),
StrToFloat(Edit9.Text,xDefaultFormatSettings)) then
Last edit: 5 months 1 week ago by Peter Heckert.