Marc Guillot
Marc Guillot

Reputation: 6455

Override regional settings at the application start up

I want to force my application to always use the Spanish regional settings, using the FormatSettings global variable, but the application ignores those settings. Do you know what I have missed ?.

program TestProject;

uses
  Vcl.Forms,
  SysUtils,
  Rutinas in 'Rutinas.pas',
  Conexion in 'Conexion.pas' {dmConexion: TDataModule},
  MainForm in 'MainForm.pas' {frmMainForm};

{$R *.res}

begin
  Application.Initialize;

  FormatSettings := TFormatSettings.Create('es-ES');

  Application.MainFormOnTaskbar := True;
  Application.Title := Application_Name;
  Application.CreateForm(TdmConexion, dmConexion);
  Application.CreateForm(TfrmMainForm, frmMainForm);
  Application.Run;
end.

Thank you.

PS: I know that FormatSettings is not recommended because it's not thread safe, but it shouldn't be a problem here because I only change it once at the application start up, any other time that I need a customized conversion I use a local TFormatSettings variable.

Upvotes: 1

Views: 1353

Answers (1)

Marc Guillot
Marc Guillot

Reputation: 6455

I apologize, the problem wasn't in Delphi but on the DevExpress controls that I use to present the data.

DevExpress uses their own format settings: https://www.devexpress.com/Support/Center/Question/Details/A517/how-to-use-custom-formats-for-editors

Now this works correctly :

program TestProject;

uses
  Vcl.Forms,
  SysUtils,
  cxFormats,
  Rutinas in 'Rutinas.pas',
  Conexion in 'Conexion.pas' {dmConexion: TDataModule},
  MainForm in 'MainForm.pas' {frmMainForm};

{$R *.res}

begin
  Application.Initialize;

  FormatSettings := TFormatSettings.Create('es-ES');
  Application.UpdateFormatSettings := False;
  cxFormatController.BeginUpdate;
  cxFormatController.UseDelphiDateTimeFormats := True;
  cxFormatController.EndUpdate;
  cxFormatController.GetFormats;
  cxFormatController.NotifyListeners;

  Application.MainFormOnTaskbar := True;
  Application.Title := Application_Name;
  Application.CreateForm(TdmConexion, dmConexion);
  Application.CreateForm(TfrmMainForm, frmMainForm);
  Application.Run;
end.

Upvotes: 4

Related Questions