6

Moving from Delphi XE to XE5.

Label1.Caption:= 'Today''s day is '+LongDayNames[DayOfWeek(Date)];

'LongDayNames' no longer works. I see that Delphi put these in my uses:

System.SysUtils, System.Variants, System.Classes,

How do I find 'LongDayNames' so it works?

Ken White
  • 123,280
  • 14
  • 225
  • 444
user3470296
  • 79
  • 1
  • 2
  • 2
    `LongDayNames` were marked as deprecated even in XE. You should have been given a hint to use `FormatSettings.LongDayNames` when compiling your sources. Well, you have been warned. – Uwe Raabe Mar 27 '14 at 21:02
  • @Uwe And Embarcadero have made it even harder to move from D2007. I wanted to do a quick *proof of concept* port to XE5 to look at FireDAC performance and had to give up as it wasn't going to be **quick**. Remember, not everyone steps though every version. – Gerry Coll Mar 27 '14 at 21:14

2 Answers2

7

You use the values contained in the SysUtils.FormatSettings global variable:

Label1.Caption := SysUtils.FormatSettings.LongDayNames[DayOfWeek(Date)]; 

This allows them to be localized based on the current Windows locale.

Note that use of the global SysUtils.FormatSettings is not thread-safe. To create a thread-safe copy of the format settings, create a local copy of TFormatSettings using TFormatSettings.Create as described in the documentation here instead.

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Is that global variable still the right way to do it? I recall Remy saying that it went completely in XE5, or did I remember wrong. – David Heffernan Mar 27 '14 at 21:18
  • @DavidHeffernan, the global variable ist still available in XE5. There is only warning that using it is not thread-safe. – Uwe Raabe Mar 27 '14 at 21:39
  • 2
    @David: No, it's still there. (The code was quickly tested in XE5 before posting.) It's indeed not thread-safe (threads should create a new, local instance of `TFormatSettings` and use it instead), but the question asked is general in scope. I linked the documentation for more details. What went away in XE5 was the global `LongDayNames` variable itself; it's now only available through `TFormatSettings` (and the global instance of it contained in `SysUtils.FormatSettings` is one way to get to them). – Ken White Mar 27 '14 at 21:44
0

I have personalized to my country Brazil the long names using this way: remember do add in uses System.SysUtils

FormatSettings.LongDayNames[1] := 'Domingo';
FormatSettings.LongDayNames[2] := 'Segunda';
FormatSettings.LongDayNames[3] := 'Terça';
FormatSettings.LongDayNames[4] := 'Quarta';
FormatSettings.LongDayNames[5] := 'Quinta';
FormatSettings.LongDayNames[6] := 'Sexta';
FormatSettings.LongDayNames[7] := 'Sábado';