I have edith, I enter the number there. I made this code, but when I enter it, an error appears, I understand that this is because of StringReplache because I use it twice, how to do everything in one code to remove all spaces and change the comma to a period

procedure TForm26.btn1Click(Sender: TObject); var t1: string; begin t1 := StringReplace(edt2.Text, ',', '.', [rfReplaceAll]); t1 := Trim(edt2.Text); t1 := StringReplace(t1, ' ', '', [rfReplaceAll]); qry1.SQL.Clear; qry1.SQL.Add('INSERT INTO Facial(summa) VALUES('+#39+t1+#39+')'); qry1.ExecSQL; end; 

when I enter a number with a comma, I get an error message

enter image description here

  • And the number that you enter, with a dot or a comma? Both options do not work? And if just a number, without a separator, doesn't work either? Questions asking for help with debugging (“why does this code not work?”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question. Questions without an explicit description of the problem are useless for other visitors. - Kromster
  • I enter the number with a comma, spaces on the right and left sides and between the numbers work - delphi
  • And the number that you enter, with a dot or a comma? Try both options, both do not work? And if just a number, without a separator, doesn't work either? - Kromster
  • I enter the number with it and it does not work, the code says that the comma should be changed to dots. integer and with a point of operation - delphi
  • Databases do not like dynamic SQL very much; in a day, you can make the DBMS server slow down with such queries. Better to do parametric selections. - nick_n_a

1 answer 1

The code needs to be corrected, because you wipe the results of the first StringReplace , and better like this (edit, taking into account the @Kromster remark):

 t1 := Trim(edt2.Text); t1 := StringReplace(t1, ',', DecimalSeparator, [rfReplaceAll]); t1 := StringReplace(t1, '.', DecimalSeparator, [rfReplaceAll]); t1 := StringReplace(t1, ' ', '', [rfReplaceAll]); 
  • Alexander Chernin Your answer does not work - delphi
  • @Kromster you are right, of course you need to change to DecimalSeparator - Alexander Chernin