[UNSOLVED] Replace the decimal point with a comma in a DBEDIT lazarus / 31-LCL ---------------------------------------------------------------------- Ever · 2024-04-27 01:17 Hello everyone       I need to know if there is any way so that when I am writing a numerical value in a DBEDIT (this DBEDIT is linked to a numerical field of a MySQL table), and I need to add the decimal part, when I press the point on the keyboard, it gives me a eat. I don't want to have to resort to changing Windows settings for this purpose. I want to do it by programming.     First of all, Thanks ---------------------------------------------------------------------- Thaddy · 2024-04-27 04:25 Add a field OldFormatSettings:TFormatSettings; to your form. Then use the OnEnter and Onleave events from the TDbEdit like so: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Edit1Enter(Sender: TObject);begin   OldFormatSettings:=FormatSettings;   FormatSettings.DecimalSeparator:='.';end; procedure TForm1.Edit1Exit(Sender: TObject);begin  FormatSettings := OldFormatSettings;end;This temporary changes the DecimalSeparator to a dot, but restores it to the system default after leaving the TDbEdit. The rest of your controls in your application will behave according  to the system default settings. Tip: combine it with the CustomEditMask and EditMask properties. ---------------------------------------------------------------------- Ever · 2024-04-27 13:02 Thanks for your reply       Unfortunately that doesn't work, what I want is to be able to press the key corresponding to the dot on the keyboard and have a comma typed instead.     I have tried using the DBEDIT OnKeyPress event to replace the dot with the comma in the following way Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i        if Key=#46 then Key:=#44;     but it does not work. If I carry that same action in a TEdit component it takes it perfectly. ---------------------------------------------------------------------- cdbc · 2024-04-27 13:18 Hi Hmmm... You could try 'OnKeyDown' instead of keypress and then something like this:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses LCLTypes; // i think this is the one with the VK_ keycodes...procedure TForm1.DBEdit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin  case Key of                         VK_Punctuation: Key:= VK_Comma; // not sure about the names  end; end; Untested code, but worth a try, I think.... Regards Benny ---------------------------------------------------------------------- Ever · 2024-04-27 14:05 Hello Benny       It didn't work either. I make the note that the constants are no longer used, check the LCLType code, VK_Comma is commented and VK_Punctuation does not appear, I still replaced the constants with the respective values in ASCII code and it didn't work. I think the problem is due to the fact that it is a dbedit and is linked to a database field. If it's not possible, I'll unfortunately leave it that way.     Thanks for your support ---------------------------------------------------------------------- wp · 2024-04-27 15:54 In which country are you? What is the decimalseparator on your system? What does the following mini project print on the screen, a comma or a point? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1;uses  SysUtils;begin  WriteLn(Formatsettings.DecimalSeparator);  ReadLn;end.If it is a comma then your system is set up to want floating point values with a decimal comma. But then why do you want to enter a decimal point? According to https://dev.mysql.com/doc/refman/8.0/en/fixed-point- types.html, MySQL (your database system?) stores floating point values in a binary format in which it does not matter whether there is a comma or point decimal separator. Only the conversion between text and float is important. This is done by the TDBEdit which is well-prepared for this issue and is able to convert the entered string (with a comma or point, depending on your FormatSettings) into a valid binary representation. ---------------------------------------------------------------------- RayoGlauco · 2024-04-27 16:47 Note that the virtual key codes are not ASCII codes. See this: https://learn.microsoft.com/en- us/windows/win32/inputdev/virtual-key-codes You can use VK_OEM_COMMA and VK_OEM_PERIOD in KeyDown events ---------------------------------------------------------------------- Ever · 2024-04-27 21:03 I completely understand wp's point of view and your analysis is completely accurate. In Venezuela all PCs are configured with the comma for the decimal part and it happens that out of habit, 100% of the users got used to typing the decimal point when they use Excel, and it places the comma automatically, and it is difficult for them to understand that In the case of software developed with Pascal, not to mention other languages, they must type the comma and not the point in the decimal part, most people assume that for any software it is how Excel does it. For this reason I wanted to try to ensure that the behavior that is natural for people, such as in Excel, is the same in the software I develop. ---------------------------------------------------------------------- RayoGlauco · 2024-04-27 21:17 After putting the correct names, @cdbc's code would look like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses LCLType; //  VK_ keycodes...procedure TForm1.DBEdit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin  case Key of                      VK_OEM_PERIOD : Key:= VK_OEM_COMMA;   end;end; ---------------------------------------------------------------------- wp · 2024-04-27 22:24 Quote from: Ever on April 27, 2024, 11:03:30 pmIn Venezuela all PCs are configured with the comma for the decimal part and it happens that out of habit, 100% of the users got used to typing the decimal point when they use Excel, and it places the comma automatically In German, this does not work. We also have the comma as decimal separator, but the point as date separator. So, when I type "1.2" it gets converted to "01.Feb"... There would also be a problem with the thousand separator which is a point here. So, if Excel were allowed to convert an entered decimal point to a comma there would be an ambiguity: When I type "1.200" would this mean "one-point-two" or "one-thousand-two-hundred"? In my opinion, attempts to make numeric input more flexible regarding the decimal separator are risky. When you are sure that all users type a decimal point although the country settings of the OS are set up for a decimal comma you should not rely on individual software to take care, but really change the country settings of the operating system to a decimal separator. Then everything would be consistent again for all applications. ---------------------------------------------------------------------- Ever · 2024-04-27 22:30 In the case of the thousands separator, it is the point, so it did not open ambiguity. But given all the options, I have decided to let it work as it does, and let the user adapt. Thank you all for your support ---------------------------------------------------------------------- jamie · 2024-04-28 10:57 You can't use the "OnChange" event in the DBEdit and filter the first "." with a replacement of a "," ? ---------------------------------------------------------------------- Ever · 2024-05-02 23:15 Thank you all for your support, I made the decision to leave it as it works in dbedit ---------------------------------------------------------------------- jcmontherock · 2024-05-03 09:10 I'm using:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function EditNum(lValue: Double): String;var  fs: TFormatSettings;begin  result := '0';  if lValue = 0  then  exit;  {$WARNINGS OFF}{$HINTS OFF}  GetLocaleFormatSettings(GetSystemDefaultLCID, fs);  {$WARNINGS ON}{$HINTS ON}  fs.ThousandSeparator := '''';  fs.DecimalSeparator  := '.';  result := FormatFloat('###,###,###.##', lValue, fs); // ,: thousand separator, .: decimal separatorend;