Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2020-04

FormatSettings in library vs application

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

It's been over a year since I looked at any Object Pascal code, so a bit rusty. [bows his head in shame] :-)

I'm maintaining a library that uses the function seen below. I any FPC (or Lazarus) application uses this library (eg: via a lcl package).

1) Will this function change the ShortDateFormat for the whole application, or is the scope just inside that function?

2) Is the better solution to define a local TFormatSettings, define the ShortDateFormat for that record, and then pass that to DateToStr as the 2nd parameter?

{convert date to string with 4-digit year and 2-digit month}
function OgFormatDate(Value : TDateTime) : string;
var
  S : string;
begin
  FormatSettings.ShortDateFormat := 'yyyy-mm-dd';
  Result := DateToStr(Value);
end;

Regards,
Graeme

Reply by email

Jonas Maebe
to Graeme Geldenhuys
Graeme Geldenhuys wrote
1) Will this function change the ShortDateFormat for the whole application, or is the scope just inside that function?

It will be just that library, unless the library is compiled as a dynamic package.

2) Is the better solution to define a local TFormatSettings, define the ShortDateFormat for that record, and then pass that to DateToStr as the 2nd parameter?

That would indeed be best.

Jonas

Reply by email