You've written the date/time to the file as text. And formatted it using the locale settings of the user who created that file. You are doomed to fail to read this file reliably since different users have different locale settings. You need to use a robust format for the date that does not depend on locale.
The two options that seem most natural:
- Store as a floating point value, using the underlying representation of
TDateTime
. - Store as text using a pre-determined format.
For option 1 you'll need to make sure you use a pre-determined decimal separator to avoid the exact same problem you have now! That means you'll need to perform your own conversion between TDateTime
and string
because the WriteFloat
and ReadFloat
methods use the global format settings which are locale dependent. There are overloads of FloatToStr
and StrToFloat
in SysUtils
that accept a format settings parameter.
For option 2, the RTL contains various functions to perform date/time conversions using specified formats. There are overloads of DateTimeToStr
and StrToDateTime
in SysUtils
that accept a format settings parameter.
Option 2 is to be preferred if you wish the file to be easily read or edited by a human.