Link to home
Start Free TrialLog in
Avatar of r2kc
r2kc

asked on

TFormatSettings.DecimalSeparator not working in Delphi XE7

Hi

I am trying to change the DecimalSeparator with the following code:

procedure TWealthForm.FormCreate(Sender: TObject);
var
  SystemDecimalSep: Char;
  fs: TFormatSettings;
begin
  fs := TFormatSettings.Create();
  SystemDecimalSep := fs.DecimalSeparator;
  fs.DecimalSeparator := '.';
end;

It does not seem to work though. The default on Windows is a comma and I want to change it to a decimal point. Can anyone please assist with this?

Many Thanks.
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Try to not create new instance of TFormatSettings. Change existing one:
SystemDecimalSep := SysUtils.FormatSettings.DecimalSeparator;
SysUtils.FormatSettings.DecimalSeparator := '.';
 Application.UpdateFormatSettings := False; //block refreshing format settings

Open in new window


Why do you need to change decimal separator? For viewing or editing?
There are other solutions....
Avatar of r2kc
r2kc

ASKER

Hi Sinisa

Thanks for the response.

The above still does not work for the TdxDBGridColumn.

I need to change the decimal separator for editing purposes. I want the user to enter a decimal value into a column in the column.

Thanks.
Maybe you can check user enter on KeyPress event:

procedure ColumnKeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9', #8, '.'] then Key:=#0;
end;

Open in new window


... this cod will allow only point  as input character.
Avatar of r2kc

ASKER

This bit of code is also not working. I suspect that there may be an issue with the third party component that I am using. It will not accept the decimal point as the decimal separator if the regional settings are set to something else. I will try another grid component.

Thanks for the responses.
yes, that could be solution too... or you can contact grid developer to help you (or make changes...)
Avatar of r2kc

ASKER

Thanks. I'll try that.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.