Member Avatar for Member #1089874

Just started to use Delhi XE4 and found that LongMonthNames wouldn't compile. Error E2003 Undeclared Indentifier 'LongMonthNames'.
Went to XE3 with the same error, Delphi 2009 with no problem.
Just create a new VCL project with only statment S:=LongMonthNames[12]; will give the error. System.SysUtils is used and the definition is there.
Any clue sombody?
Thanks Bo

Dani AI

Generated

Short answer: this is a deliberate RTL change introduced around XE3 — the old global date/locale variables were removed and the locale strings (including long month names) are now part of a TFormatSettings record. That is why code that referenced the old global identifier fails to compile in XE3/XE4. (stackoverflow.com)

The correct model now is to read the month names from a format-settings record. TFormatSettings includes the long-month-name array and the RTL provides a global record for convenience, but the recommended pattern is to create or obtain a TFormatSettings instance and use the thread-safe overloads of the formatting routines. This avoids races if the global settings are changed at runtime. (docwiki.embarcadero.com)

Practical, thread-safe example (works in XE3/XE4 and later): create a local TFormatSettings and use the overload that accepts it so month names come from that record:

var
  FS: TFormatSettings;
  MonthName: string;
begin
  FS := TFormatSettings.Create;               // initialise for current locale
  MonthName := FormatDateTime('mmmm', EncodeDate(2021, 12, 1), FS);
end;

The mmmm specifier returns the full month name from the record you pass. (docwiki.embarcadero.com)

If you need source compatibility when migrating older Delphi code, use conditional compilation around the compiler version (XE3 corresponds to CompilerVersion 24) and prefer calling the overload that accepts a TFormatSettings record on XE3+. That keeps behaviour consistent while you update code. (docwiki.embarcadero.com)

Note: ’s pointer to the format-settings approach is the right fix for the compile error reported by . For long-running or multi-threaded apps, avoid writing the global FormatSettings; create and pass a local TFormatSettings (or initialise one once and reuse it) to keep conversions deterministic. (docwiki.embarcadero.com)

Recommended Answers

All 2 Replies

Try using FormatSettings.LongMonthNames[12]. I assume you declared S as a String.

Member Avatar for Member #1089874

You are correct, problem solved, thank's a lot!
I couldn't read the help text correct...
Regards Bo

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.