Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Win 7 Invalid date Error



Permlink Replies: 4 - Last Post: Jul 2, 2014 11:42 AM Last Post By: Remy Lebeau (Te...
boopathi s

Posts: 3
Registered: 2/6/07
Win 7 Invalid date Error
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 2, 2014 4:26 AM
Hi,

Recently we are migrating the delphi 7 application from windows XP to Windows 7 and we are getting the Invalid date error while converting the string to date using "StrToDateTime" function.

We are setting the shortdatetime as below in Formshow in Mainform and it is worked fine in Windows XP and it is throwing error in Windows 7

DateSeparator := '-';
ShortDateFormat := 'dd-mm-yyyy';

Can you please help to resolve this issue?
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: Win 7 Invalid date Error
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 2, 2014 4:54 AM   in response to: boopathi s in response to: boopathi s
boopathi s wrote:

Hi,

Recently we are migrating the delphi 7 application from windows XP to
Windows 7 and we are getting the Invalid date error while converting
the string to date using "StrToDateTime" function.

We are setting the shortdatetime as below in Formshow in Mainform and
it is worked fine in Windows XP and it is throwing error in Windows 7

DateSeparator := '-';
ShortDateFormat := 'dd-mm-yyyy';

Can you please help to resolve this issue?

I have no access to Delphi 7. However, in newer versions I would try to
use:

   Application.UpdateFormatSettings := False; 
   DateSeparator := '-';
   ShortDateFormat := 'dd-mm-yyyy'; 


By setting the Application.UpdateFormatSettings to false you are
telling that the format settings should not to be updated when the
application receives a WM_WININICHANGE message from Windows.
boopathi s

Posts: 3
Registered: 2/6/07
Re: Win 7 Invalid date Error
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 2, 2014 5:20 AM   in response to: Lajos Juhasz in response to: Lajos Juhasz
It means when we set Application.UpdateFormatSettings := False; application will not look into the default values from windows and it will consider only the values what we set in application, Right?
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: Win 7 Invalid date Error
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 2, 2014 9:12 AM   in response to: boopathi s in response to: boopathi s
boopathi s wrote:

It means when we set Application.UpdateFormatSettings := False;
application will not look into the default values from windows and it
will consider only the values what we set in application, Right?

If after settings UpdateFormatSettings to false the format is changed
then most probably some third party library code is changing it. When
the user or other application changes the system wide settings then a
WM_WININICHANGE is sent to every running application (that you can
block with UpdateFormatSettings).

I did a bit of testing on Windows 8 (Delphi XE5) and got a very unusual
result. When I customize the region settings and set short date format
to "dd.MM.yyyy" the formatSettings.ShortDateFormat become "dd/MM/yyyy/"
and FormatSettings.DateSeparator ".".

Luckily in my application Application.UpdateFormatSettings is set to
false.

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Win 7 Invalid date Error
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 2, 2014 11:42 AM   in response to: boopathi s in response to: boopathi s
boopathi wrote:

Can you please help to resolve this issue?

Can you show an example string that is not converting correctly?

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02