Forum > LCL

[UNSOLVED] Replace the decimal point with a comma in a DBEDIT

(1/3) > >>

Ever:
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:
Add a field OldFormatSettings:TFormatSettings; to your form.
Then use the OnEnter and Onleave events from the TDbEdit like so:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---       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:
Hi
Hmmm...
You could try 'OnKeyDown' instead of keypress and then something like this:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
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

Navigation

[0] Message Index

[#] Next page

Go to full version