How to change the decimal separator for a numeric key in my Delphi application?

In my country, the decimal separator is " , ". One of my clients would like to have it as a symbol . . What needs to be done to change the decimal separator to " . "?

I tried this:

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  DecimalSeparator := '.';
  Application.UpdateFormatSettings := True;
end;

But this code only helps partially. I see a " . " In gird in the float fields. However, when the user presses a numeric keybord key . , a comma is sent despite the settings. This is a non-grid issue, I tested this on a KeyPress event in the form.

I am using Delphi 2007, thanks for your help.

+3
source share
2

, UpdateFormatSettings false! , DecimalSeparator reset Windows (, , ​​( Win + L), ). - true, false, DecimalSeparator.

-, DecimalSeparator Delphi (, FloatToStr FormatFloat). , (.), (, , . ,), OnKeyPress:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = ',' then
    Key := '.'
end;

- , ., , .

( ) OnKeyDown :

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  msg: TMsg;
begin
  if Key = VK_DECIMAL then
  begin
    PeekMessage(msg, Edit1.Handle, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE);
    SendMessage(Edit1.Handle, WM_CHAR, ord('.'), 0);
  end;
end;
+9

char Delphi, , .

. OnKeyPress.

- KeyDown/Up , , .
TranslateMessage http://msdn.microsoft.com/en-us/library/ms644955(VS.85).aspx
, , TranslateMessage, , numpad, . , , .

+1

Source: https://habr.com/ru/post/1769343/


All Articles