From 35a21de57cb403eb05e48fd6e65e77eb3019f405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Van=20Canneyt?= Date: Wed, 19 Feb 2025 20:36:54 +0100 Subject: [PATCH] * Allow TFormatSettings.Create with string (using callback) --- rtl/objpas/sysutils/sysint.inc | 11 +++++++++++ rtl/objpas/sysutils/sysinth.inc | 9 ++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/rtl/objpas/sysutils/sysint.inc b/rtl/objpas/sysutils/sysint.inc index 1f333c3788..1905b2d503 100644 --- a/rtl/objpas/sysutils/sysint.inc +++ b/rtl/objpas/sysutils/sysint.inc @@ -54,6 +54,17 @@ begin Result:=DefaultFormatSettings; end; +class function TFormatSettings.Create(const LocaleName: string): TFormatSettings; +begin + // Catch + if LocaleName.StartsWith('en-US') then + Result:=TFormatSettings.Invariant + else if assigned(InitFormatSettingsHook) then + InitFormatSettingsHook(LocaleName,Result) + else + Raise ENotSupportedException.Create('No support for transforming locale name to format settings') +end; + procedure InitInternationalGeneric; begin fillchar(SysLocale,sizeof(SysLocale),0); diff --git a/rtl/objpas/sysutils/sysinth.inc b/rtl/objpas/sysutils/sysinth.inc index d48bb0cc90..a2f647434e 100644 --- a/rtl/objpas/sysutils/sysinth.inc +++ b/rtl/objpas/sysutils/sysinth.inc @@ -31,6 +31,8 @@ type TMonthNameArray = array[1..12] of string; TWeekNameArray = array[1..7] of string; + { TFormatSettings } + TFormatSettings = record CurrencyFormat: Byte; NegCurrFormat: Byte; @@ -55,9 +57,11 @@ type class function Invariant : TFormatSettings; static; class function Create: TFormatSettings; overload; static; inline; // class function Create(Locale: TLocaleID): TFormatSettings; overload; platform; static; - // class function Create(const LocaleName: string): TFormatSettings; overload; static; + class function Create(const LocaleName: string): TFormatSettings; overload; static; end; + TInitFormatSettingsHook = Procedure(const aLocale : string; var aSettings : TFormatSettings); + var DefaultFormatSettings : TFormatSettings = ( CurrencyFormat: 1; @@ -84,7 +88,10 @@ var TwoDigitYearCenturyWindow: 50; ); + FormatSettings : TFormatSettings absolute DefaultFormatSettings; + InitFormatSettingsHook : TInitFormatSettingsHook; + { --------------------------------------------------------------------- Date formatting settings ---------------------------------------------------------------------}