Forum
× CodeOcean Samples and DocFactory discussions and suggestions

Question DMath example Mandel - StrToFloat raises exception

  • Peter Heckert
  • Peter Heckert's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
More
6 days 12 hours ago - 6 days 12 hours 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: 6 days 12 hours ago by Peter Heckert.

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Away
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
6 days 11 hours ago #13314 by Sternas Stefanos
Replied by Sternas Stefanos on topic DMath example Mandel - StrToFloat raises exception
Thanks Sir
we add your fix to Lab CT

PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.