3
votes

i have this procedure:

procedure Initialize(out FormatSettings: TFormatSettings);
const
  LongDayNamesEx : array [1..7] of string = ('Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato', 'Domenica');
  LongMonthNamesEx : array [1..12] of string = ('Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre');
begin
  FormatSettings := TFormatSettings.Create;
  with FormatSettings do
  begin
    LongDayNames := LongDayNamesEx;
    LongMonthNames := LongMonthNamesEx;
  end;
end;

And i get an error about incompatible types (E2008). How i can solve this problem? I don't want to use something as:

LongDayNames[1] := 'Lunedì';
LongDayNames[2] := 'Martedì';
...
LongDayNames[7] := 'Domenica';
LongMonthNames[1] := 'Gennaio';
LongMonthNames[2] := 'Febbraio';
...
LongMonthNames[12] := 'Dicembre';

if not stricly necessary. Thanks for help.

3

3 Answers

5
votes

You can do like this:

type
  TDayNameArray = array[1..7] of string;
const
  LongDayNamesEx: TDayNameArray = ('Måndag', 'Tisdag', 'Onsdag', 'Torsdag',
    'Fredag', 'Lördag', 'Söndag');
var
  fs: TFormatSettings;
begin
  TDayNameArray(fs.LongDayNames) := LongDayNamesEx;
3
votes

Andreas gave you a good answer to the direct question that you asked.

Taking a different approach, I think you could solve your problem more easily by passing the locale when you initlialise the object. For example:

FormatSettings := TFormatSettings.Create('it-IT');

for Italian. Then the system will fill out the locale specific settings, day names, month names etc.

Or perhaps you would use the overload that takes a locale ID is more appropriate. No matter, you surely get the idea.

0
votes

To answer the question you asked directly, the obvious solution is to use a for loop. Combine a record helper and open array parameters to make it more easily called:

type
  TTFormatSettingsHelper = record helper for TFormatSettings
    procedure SetLongDayNames(const Values: array of string);
  end;

procedure TTFormatSettingsHelper.SetLongDayNames(const Values: array of string);
var
  Index: Integer;
  Value: string;
begin
  Assert(high(Values)-low(Values)
    = high(Self.LongDayNames)-low(Self.LongDayNames));

  Index := low(Self.LongDayNames);
  for Value in Values do
  begin
    Self.LongDayNames[Index] := Value;
    inc(Index);
  end;
end;

And then to call this you simply write:

FormatSettings.SetLongDayNames(['Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 
  'Venerdì', 'Sabato', 'Domenica']);