Board index » delphi » Set Windows Shortdateformat (not just for Delphi session)

Set Windows Shortdateformat (not just for Delphi session)

How do I change the windows shortdateformat using Delphi. I need
to toggle this for a non-Delphi app that uses mm/dd/yy whilst all
others use dd/mm/yy

Quote

> Why does the following do nothing:

> > > var sDateFormat:pchar;
> > > begin
> > >   MyMessage:='mm/dd/yy';
> > >   SetLocaleInfo(
> > >    LOCALE_USER_DEFAULT, LOCALE_SDATE, sDateFormat);

> In article <93g8rj$j4...@bornews.inprise.com>, Richard C Haven
> wrote:
> > Just set the unit variables in SysUtils.PAS.

How do I do this?  I don't follow what to do. In sysutils.pas
there
is the following:

ShortDateFormat := TranslateDateFormat(GetLocaleStr(DefaultLCID,
LOCALE_SSHORTDATE, 'm/d/yy'));

I tried to do what I need by adding string variables as follows:

  USShortDateFormat :=
TranslateDateFormat(GetLocaleStr(DefaultLCID,
LOCALE_SSHORTDATE, 'mm/dd/yy'));
  UKShortDateFormat :=
TranslateDateFormat(GetLocaleStr(DefaultLCID,
LOCALE_SSHORTDATE, 'dd/mm/yy'));

Doesn't do anything.

Pat Bell

 

Re:Set Windows Shortdateformat (not just for Delphi session)


Quote
"P.S.Bell" wrote:
> How do I change the windows shortdateformat using Delphi. I need
> to toggle this for a non-Delphi app that uses mm/dd/yy whilst all
> others use dd/mm/yy

You can change your parameters locally, but not those of another
application. To change them for the other application, you modify
the registry, but such a change applies to all applications.

Good luck.

Kurt

Re:Set Windows Shortdateformat (not just for Delphi session)


Hi Pat,

P.S.Bell wrote in <VA.00000307.0026d...@patbell.demon.co.uk>:

Quote
> How do I change the windows shortdateformat using Delphi.

You can set the locale windows format to dd/mm/yy:
  SetLocaleInfo(GetThreadLocale, LOCALE_SSHORTDATE, 'dd/MM/yy');
  SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0,
    SMTO_ABORTIFHUNG, 1000, PDWord(Nil)^);
This modify the systemwide settings for the current user and have
consequences for all application using this settings.

A Delphi application call GetFormatSettings, if
Application.UpdateFormatSettings set to True (default). All changes on
any format variables are reset to the windows defaults.

Quote
> I need
> to toggle this for a non-Delphi app that uses mm/dd/yy whilst all
> others use dd/mm/yy

I can not recognize any possibility to do this. If the most application
use 'dd/mm/yy', then the locale settings are very likely set to
'dd/MM/yy' and the non-Delphi application is not able to use any date
format except 'mm/dd/yy'.

Quote
> I tried to do what I need by adding string variables as follows:

>   USShortDateFormat :=
> TranslateDateFormat(GetLocaleStr(DefaultLCID,
> LOCALE_SSHORTDATE, 'mm/dd/yy'));
>   UKShortDateFormat :=
> TranslateDateFormat(GetLocaleStr(DefaultLCID,
> LOCALE_SSHORTDATE, 'dd/mm/yy'));

> Doesn't do anything.

Yes, It's do, what you have wrote. ;-)

This is the same like (in most cases):
  USShortDateFormat := ShortDateFormat;
  UKShortDateFormat := ShortDateFormat;

You set USShortDateFormat and UKShortDateFormat to the locale format.
The last parameter is only used, if any error during get the value.

By Peter.

Re:Set Windows Shortdateformat (not just for Delphi session)


Hi Kurt,

Kurt Barthelmess (TeamB) wrote in <3A6F9564.FF90A...@compuserve.com>:

Quote
> To change them for the other application, you modify
> the registry,

This is not a good recommendation. The official way is safe and easy:

  SetLocaleInfo(GetThreadLocale, LOCALE_SSHORTDATE, 'yyyy-MM-dd');
  SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0,
    SMTO_ABORTIFHUNG, 1000, PDWord(Nil)^);

Quote
> but such a change applies to all applications.

This is another problem. E.g., I do not tolerate any application on my
computer, it's changed any system settings without my permission.

By Peter.

Re:Set Windows Shortdateformat (not just for Delphi session)


Quote
> This is another problem. E.g., I do not tolerate any application on my
> computer, it's changed any system settings without my permission.

I agree but if that is what they demand...

Pat Bell

Re:Set Windows Shortdateformat (not just for Delphi session)


Quote
"P.S.Bell" <p...@PatBell.demon.co.uk> wrote in message

news:VA.0000030c.00e939bf@patbell.demon.co.uk...

Quote
> > This is another problem. E.g., I do not tolerate any application on my
> > computer, it's changed any system settings without my permission.

> I agree but if that is what they demand...

On the other hand, I write applications which run solo on dedicated machines
which are shipped as a turnkey package. Any customer who confuses these
products with PCs and installs and runs other software than ours, voids his
warranty.

Bill

Other Threads