First of all, you should set UpdateFormatSettings
to false
! If this property is true, the DecimalSeparator
will be reset to the Windows default one every now and then (for instance, every time you lock the workstation (using Win+L) and then unlock it again). The default value is true
, so you need to set it to false
when you want to override DecimalSeparator
.
Secondly, the DecimalSeparator
is used by Delphi routines when formatting floating-point numbers as strings (e.g. when using FloatToStr
or FormatFloat
). To make the decimal separator key on the numeric keypad result in a point (.
) and not the OS default character (which is probably either .
or ,
), you can handle the OnKeyPress
event:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = ',' then
Key := '.'
end;
But be cautious - this will replace all ,
with .
, even those inserted by the comma key on the alphabetical part of the keyboard.
A more advanced (and safer) method is to handle the OnKeyDown
event like this:
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;