I normally keep the setting in a variable, then change it to something I know how to handle, and reset it when I'm done. This way you won't have to retrieve the locale/user date setting.
Main Topics
Browse All Topicsrunning a service on win2k sp4
sometimes ShortDateFormat is OK (in my case it's dd.mm.yyyy)
but very often the format is different .. like 'ddd mm yyyy' or whatever it is
ofcourse in the later case StrToDate raises an exception
where is this format read from ? every user can have different locale settings .. where's the setting for SYSTEM or computer global setting
I really don't want to set ShortDateFormat everytime before I call DateToStr nor use the overloaded version with FormatSettings
actually the only way I could solve this issue was with the overlaoded version with FS (in one project)
but the same problem will arise in all other projects .. which are much larger
sooo .. where can I set these global globale settings ?
and it's really weird .. some threads run in the right LCID and some don't .. I have no idea what affects this
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi,
I had a similar problem with TDateTimePicker component on every new form when the process was running under another users account. ShortDateFormat was correct but the date format in that component was different. I solved it another way but you may check HKEY_USERS\.DEFAULT\Contro
Regards, Geo
pritaeas: yes well .. already did that but I can't control vcl methods .. like TParam.AsString which calls StrToSQLTimeStamp .. don't know when it will be called
I thought of monitoring the change of ShortDateFormat or some hack around it .. no pretty solutions yet :/
geobul: did that and am waiting for results
Lee,
If you set the ShortDateFormat ONCE then you should be fine in your service application. This value (and a few others) gets loaded via a call to GetFormatSettings, which is made in only 2 places:
1.) in the initialization of the SysUtils unit
2.) can also be made in the WM_WININICHANGE handling of TApplication (which is where UpdateFormatSettings is used, if false then GetFormatSettings is not called). This one does not apply to your situation.
Basically, the only place it is getting set is in the init of SysUtils, so setting it once should be suffecient.
Regarding getting the system date setting, you might try the following calls to see if any return what you are expecting:
// Get the short date format for Thread, User, and System locale, both with and without the user override
MessageBox(0, PChar(GetLocaleString(GetT
MessageBox(0, PChar(GetLocaleString(GetT
MessageBox(0, PChar(GetLocaleString(LOCA
MessageBox(0, PChar(GetLocaleString(LOCA
MessageBox(0, PChar(GetLocaleString(LOCA
MessageBox(0, PChar(GetLocaleString(LOCA
function GetLocaleString(Locale: LCID; LCType: DWORD): String;
var lpBuffer: Array [0..1023] of Char;
dwReturn: Integer;
begin
// Get the locale info
dwReturn:=GetLocaleInfo(Lo
// Check return value
if (dwReturn = 0) then
// Raise exception using last error
RaiseLastWin32Error
else
begin
// Null terminate
lpBuffer[dwReturn]:=#0;
// Return the string
result:=StrPas(@lpBuffer);
end;
end;
----------
Hope this helps,
Russell
Aaa, yep. Sorry, I forgot you are writting a service...
There were some API functions ... GetLocaleInfo and SetLocaleInfo I think. There could get/set the date format system-wide. You have to choose between system-wide settings of hard-coded date format. Sorry I can not provide you with example right now... later I hope.
I already tried setting ShortDateFormat:='dd.mm.yy
I have no clue where or what sets it to a different format
I know how to get those settings .. I was asking from where the service loads the format because it wasn't always the same
I'll dive deep into it later ..
This may help explain things a little further....
quoted from:
http://www.aimtec.com.au/a
Special problems for server applications
Delphi applications run with the locale that is the default for the currently logged in user. On NT Server this means that if somebody is logged on you will get their Regional Settings instead of the system defaults, but if nobody is logged on then the system default will be used.
For interactive applications this isn’t a problem since the same person will be logged on for the duration of the application. The problems arise with service applications like CGI scripts, where the behaviour can differ depending on whether somebody is logged in or not. Australian servers are usually set up with a system default locale of "English (Australian)" but it’s not uncommon for users to have the default locale of "English (United States)".
The problem is further compounded by the fact that if there is no logged in user the thread locale will default to the US settings, even if the system default locale is something else.
The following code at the start of your server application will help:
SetThreadLocale(LOCALE_SYS
SYSUTILS.GetFormatSettings
Application.UpdateFormatSe
This will set ShortDateFormat and the other locale dependent variables in SysUtils to reflect the system default settings, regardless of who is currently logged in. Note: it’s important to set Application.UpdateFormatSe
Unfortunately this has no effect on VarToDateTime and VarFromDateTime which like all OLE variant conversions in the VCL are hard coded to use LOCALE_USER_DEFAULT. To do a variant conversion using the system defaults you will need to directly call VariantChangeTypeEx Windows API passing it LOCALE_SYSTEM_DEFAULT instead. Note: The word from Borland is that this is a bug and that the intention is that the variant conversions should follow the thread locale. This will probably be fixed in the next version of Delphi.
-----
Regarding dbExpress, I can't say what affect it may (may not) have
Russell
tnx ... exactly what I thought is going on (somebody logged on or not)
dbExpress driver might be setting the thread locale to something it prefers .. dunno .. just a speculation .. because:
ShortDateFormat:='dd.MM.yy
ClientDataSet.Filter:=Form
believe it or not this sometimes fails .. and there are no parameters for Filter
(sqltimestamp and all those conversions are for testing .. any method that calls StrToDate failed !)
ShortDateFormat is set just before the filter is set ! I even locked ShortDateFormat with a CS .. so it must be something internal to dbExpress
so there's actually no clean solution to this .. will hack something up :)
Business Accounts
Answer for Membership
by: Lee_NoverPosted on 2004-10-19 at 02:06:33ID: 12345518
also while remote debugging I don't get these weird format settings
looks like I get the current user's formatsettings .. and no, the service isn't interactive :)