dyancer
asked on
Changing the system settings...
Hello Experts...
How can I GET and SET the system Date formating string using Windows API ... like "dd/MMMM/yy' to "dd/MM/yy'
Thanx in advance
How can I GET and SET the system Date formating string using Windows API ... like "dd/MMMM/yy' to "dd/MM/yy'
Thanx in advance
ASKER
Thank you BlackDeath for your try...
indeed before i post this question to the EX-EX i look in the win32 help and in the sysutils.pas and did not find any information on setting the system date format, but still hope there is someway to do this ...
Hassan
PS ."i've seen the code you posted at the sysutils.pas of delphi3"
indeed before i post this question to the EX-EX i look in the win32 help and in the sysutils.pas and did not find any information on setting the system date format, but still hope there is someway to do this ...
Hassan
PS ."i've seen the code you posted at the sysutils.pas of delphi3"
Hi Dyancer,
First, I think that I did not got the problem in deep (also sorry my English, I am a brazilian), so I will repeat your question on my way to see if I can understand...Sorry if my answer doesnt match with your question:
"I need to change the date formatting string from DD/MM/YY to DD/MM/YYYY, how?"
Your actual question says about convert to "DD/MMMM/YY", but I guess it is mispelling, ok ? well, the SysUtils have some variables that allow that, let's see by a example:
----------8<-------------- -
{ Set this property to False to prevent the system settings from changing (registry) }
Application.UpdateFormatSe ttings := FALSE;
DateOrder := doDMY; // or doMDY, p.ex :)
DateSeparator := '-'; // you could use a "." or "/" or any other char
DateFullYear := True;
DateLeadZero := True;
ShortDateFormat := 'dd/MM/yyyy'; // or 'dd/MM/yy' or 'd/m/yy' or 'd/mm/yyyy' etc...
Memo1.Lines.Add('The OLD Date Formatting string is: '+ShortDateFormat);
Memo1.Lines.Add(DateToStr( NOW)); // will print something like 25/12/1998
ShortDateFormat := 'dd/MM/yy' ;
Memo1.Lines.Add('The NEW Date Formatting string is: '+ShortDateFormat);
Memo1.Lines.Add(DateToStr( NOW)); // will print something like 25/12/98
---8<----------
Is it what you want ? This questions can be solved by reading the "Currency and date/time formatting variables" in D4 help (D1 too, and I guess all delphi versions).
I really hope it help you, if not, tell me ok ?
Good Lucky !
PS: here is a function to set the system Date and Time, if you dont have one, I could be useful in future:
function SetNewTime(YY,MM, DD, hh , min : word): boolean;
var
st:TSYSTEMTIME;
begin
GetLocalTime(st);
st.wYear := YY;
st.wMonth := MM;
st.wDay := DD;
st.wHour := hh;
st.wMinute := min;
Result := SetLocalTime(st) ;
end;
First, I think that I did not got the problem in deep (also sorry my English, I am a brazilian), so I will repeat your question on my way to see if I can understand...Sorry if my answer doesnt match with your question:
"I need to change the date formatting string from DD/MM/YY to DD/MM/YYYY, how?"
Your actual question says about convert to "DD/MMMM/YY", but I guess it is mispelling, ok ? well, the SysUtils have some variables that allow that, let's see by a example:
----------8<--------------
{ Set this property to False to prevent the system settings from changing (registry) }
Application.UpdateFormatSe
DateOrder := doDMY; // or doMDY, p.ex :)
DateSeparator := '-'; // you could use a "." or "/" or any other char
DateFullYear := True;
DateLeadZero := True;
ShortDateFormat := 'dd/MM/yyyy'; // or 'dd/MM/yy' or 'd/m/yy' or 'd/mm/yyyy' etc...
Memo1.Lines.Add('The OLD Date Formatting string is: '+ShortDateFormat);
Memo1.Lines.Add(DateToStr(
ShortDateFormat := 'dd/MM/yy' ;
Memo1.Lines.Add('The NEW Date Formatting string is: '+ShortDateFormat);
Memo1.Lines.Add(DateToStr(
---8<----------
Is it what you want ? This questions can be solved by reading the "Currency and date/time formatting variables" in D4 help (D1 too, and I guess all delphi versions).
I really hope it help you, if not, tell me ok ?
Good Lucky !
PS: here is a function to set the system Date and Time, if you dont have one, I could be useful in future:
function SetNewTime(YY,MM, DD, hh , min : word): boolean;
var
st:TSYSTEMTIME;
begin
GetLocalTime(st);
st.wYear := YY;
st.wMonth := MM;
st.wDay := DD;
st.wHour := hh;
st.wMinute := min;
Result := SetLocalTime(st) ;
end;
hi, magno.
i don't think it was a misspelling.
win32.hlp: Day, Month, Year, and Era Format Pictures
--
The format picture for a date string consists of a combination of null-terminated strings.
Day
d Day of the month as digits without leading zeros for single digit days.
dd Day of the month as digits with leading zeros for single digit days
ddd Day of the week as a 3-letter abbreviation as given by a LOCALE_SABBREVDAYNAME value.
dddd Day of the week as given by a LOCALE_SDAYNAME value.
Month
M Month as digits without leading zeros for single digit months.
MM Month as digits with leading zeros for single digit months
MMM Month as a three letter abbreviation as given by a LOCALE_SABBREVMONTHNAME value.
MMMM Month as given by a LOCALE_SMONTHNAME value.
Year
y Year represented only be the last digit.
yy Year represented only be the last two digits.
yyyy Year represented by the full 4 digits.
i don't think it was a misspelling.
win32.hlp: Day, Month, Year, and Era Format Pictures
--
The format picture for a date string consists of a combination of null-terminated strings.
Day
d Day of the month as digits without leading zeros for single digit days.
dd Day of the month as digits with leading zeros for single digit days
ddd Day of the week as a 3-letter abbreviation as given by a LOCALE_SABBREVDAYNAME value.
dddd Day of the week as given by a LOCALE_SDAYNAME value.
Month
M Month as digits without leading zeros for single digit months.
MM Month as digits with leading zeros for single digit months
MMM Month as a three letter abbreviation as given by a LOCALE_SABBREVMONTHNAME value.
MMMM Month as given by a LOCALE_SMONTHNAME value.
Year
y Year represented only be the last digit.
yy Year represented only be the last two digits.
yyyy Year represented by the full 4 digits.
ASKER
Dear mango...
thanx alot for trying...
indeed your answer gave me no new information about setting the system date format string.
any way, in your answer there was a mistake...
you wrote " { Set this property to False to prevent the system settings from changing (registry) }
Application.UpdateFormat Settings := FALSE;
"
this thing need some clarification:
when your program first load (if you use the sysutils unit) it read the system settings and save it into global variables, and for further use it does not read the settings again but use these global variables}
the Application.UpdateFormatS ettings := FALSE; prevent the program from responding to WM_WININICHANGED (im not sure about the spelling) and by that prevent the variables in the sysutils from changing...
to say this will not help me set the system settings :(
my problem is the "SET" half not the "GET" half of the system date string format settings.
thanx.
dyancer
thanx alot for trying...
indeed your answer gave me no new information about setting the system date format string.
any way, in your answer there was a mistake...
you wrote " { Set this property to False to prevent the system settings from changing (registry) }
Application.UpdateFormat
"
this thing need some clarification:
when your program first load (if you use the sysutils unit) it read the system settings and save it into global variables, and for further use it does not read the settings again but use these global variables}
the Application.UpdateFormatS
to say this will not help me set the system settings :(
my problem is the "SET" half not the "GET" half of the system date string format settings.
thanx.
dyancer
dyancer:
one more question:
shall this affect the whole system or just your application?
Black Death.
one more question:
shall this affect the whole system or just your application?
Black Death.
ASKER
Dear BlackDeath
I need to change the SYSTEM settings...
not the local copy of the system settings founds at sysutils unit.
thanx.
Dyancer
I need to change the SYSTEM settings...
not the local copy of the system settings founds at sysutils unit.
thanx.
Dyancer
ASKER
I'll make it worth a try for you.... adjusting points to 300 ... :)
dyancer
dyancer
well.
here's something:
HKEY_USERS\xxx\Control Panel\International
contains:
DefaultDialMode=P (e.g.)
Locale=00000407 (germany)
and nothing else in default mode
but if you change the date format settings via
control panel - country settings (intl.cpl)
a new entry occurs:
sLongDate=d. MMM yyyy
so.
obviously this is user-specific.
i think you could set the systemwide date/time-format settings by changing this entry as desired and send a wininichanged (or whatever this one's called, i can't remember right now) through your system.
o.k., this ain't api, but up to now i couldn't find something else...
does this help?
rex,
Black Death.
here's something:
HKEY_USERS\xxx\Control Panel\International
contains:
DefaultDialMode=P (e.g.)
Locale=00000407 (germany)
and nothing else in default mode
but if you change the date format settings via
control panel - country settings (intl.cpl)
a new entry occurs:
sLongDate=d. MMM yyyy
so.
obviously this is user-specific.
i think you could set the systemwide date/time-format settings by changing this entry as desired and send a wininichanged (or whatever this one's called, i can't remember right now) through your system.
o.k., this ain't api, but up to now i couldn't find something else...
does this help?
rex,
Black Death.
btw: you can use HKEY_CURRENT_USER\Control Panel\International as well.
Black Death.
Black Death.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
see also: GetLocaleInfo
finally, i've got it:
open a new project.
place 3 tbuttons and two tedits on the form.
button1.caption := 'get'
button2.caption := 'set'
button3.caption := 'exit';
here's the source:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender : TObject);
var
p: PChar;
begin
p := StrAlloc(255);
if GetLocaleInfo(LOCALE_USER_ DEFAULT, LOCALE_SLONGDATE, p, 255) > 0 then
Edit1.Text := StrPas(p)
else
case GetLastError of
ERROR_INSUFFICIENT_BUFFER: Edit1.Text := 'insufficient buffer';
ERROR_INVALID_FLAGS: Edit1.Text := 'invalid flags';
ERROR_INVALID_PARAMETER: Edit1.Text := 'invalid parameter';
end;
StrDispose(p);
end;
procedure TForm1.Button3Click(Sender : TObject);
begin
Close;
end;
procedure TForm1.Button2Click(Sender : TObject);
var
p: PChar;
begin
p := StrAlloc(255);
p := PChar(Edit2.Text);
if SetLocaleInfo(LOCALE_USER_ DEFAULT, LOCALE_SLONGDATE, p) then
MessageDlg('settings changed', mtInformation, [mbOk], 0)
else
case GetLastError of
ERROR_INSUFFICIENT_BUFFER: MessageDlg('insufficient buffer', mtError, [mbOk], 0);
ERROR_INVALID_FLAGS: MessageDlg('invalid flags', mtError, [mbOk], 0);
ERROR_INVALID_PARAMETER: MessageDlg('invalid parameter', mtError, [mbOk], 0);
end;
end;
end.
this works fine on my machine.
you can control the result in the systray-clock, the date is displayed in the format you've just defined.
cheers,
Black Death.
open a new project.
place 3 tbuttons and two tedits on the form.
button1.caption := 'get'
button2.caption := 'set'
button3.caption := 'exit';
here's the source:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender
var
p: PChar;
begin
p := StrAlloc(255);
if GetLocaleInfo(LOCALE_USER_
Edit1.Text := StrPas(p)
else
case GetLastError of
ERROR_INSUFFICIENT_BUFFER:
ERROR_INVALID_FLAGS: Edit1.Text := 'invalid flags';
ERROR_INVALID_PARAMETER: Edit1.Text := 'invalid parameter';
end;
StrDispose(p);
end;
procedure TForm1.Button3Click(Sender
begin
Close;
end;
procedure TForm1.Button2Click(Sender
var
p: PChar;
begin
p := StrAlloc(255);
p := PChar(Edit2.Text);
if SetLocaleInfo(LOCALE_USER_
MessageDlg('settings changed', mtInformation, [mbOk], 0)
else
case GetLastError of
ERROR_INSUFFICIENT_BUFFER:
ERROR_INVALID_FLAGS: MessageDlg('invalid flags', mtError, [mbOk], 0);
ERROR_INVALID_PARAMETER: MessageDlg('invalid parameter', mtError, [mbOk], 0);
end;
end;
end.
this works fine on my machine.
you can control the result in the systray-clock, the date is displayed in the format you've just defined.
cheers,
Black Death.
remark:
edit1 displays the current settings
use edit2 to enter the format string you want to assign to sLongDate.
bye,
Black Death.
edit1 displays the current settings
use edit2 to enter the format string you want to assign to sLongDate.
bye,
Black Death.
****:
in button2click in the source above the statement
StrDispose(p);
is missing at the end of the procedure.
sorry.
Black Death.
in button2click in the source above the statement
StrDispose(p);
is missing at the end of the procedure.
sorry.
Black Death.
dyancer: still alive? ;) Black
ASKER
Hello there,
I still alive, though i did not work in friday nor in saturday...
Oh... it seems like you worked alot on this...
Give me some time to check this and i'll contact you latter to tell you if it worked for me as well..
thanx
Dyancer (hassan)
PS. i knew about the settings in the registry but it does not worked for me because i couldnot force the system regional setting dialog to update it's values through the use of the WM_WININICHANGED.
I still alive, though i did not work in friday nor in saturday...
Oh... it seems like you worked alot on this...
Give me some time to check this and i'll contact you latter to tell you if it worked for me as well..
thanx
Dyancer (hassan)
PS. i knew about the settings in the registry but it does not worked for me because i couldnot force the system regional setting dialog to update it's values through the use of the WM_WININICHANGED.
ASKER
it works fine for me.
Thanx again...
dyancer
Thanx again...
dyancer
this is fragment gets the local date with the current settings:
function GetLocalDate: string;
var
Buffer: array[Byte] of Char;
iBufSize: Integer;
begin
iBufSize := GetDateFormat(GetThreadLoc
if iBufSize = 0 then
Result := IntToStr(GetLastError)
else
Result := Buffer;
end;
the second parameter is dwFlags and can be e.g.
DATE_SHORTDATE or
DATE_LONGDATE or something like that.
you can obtain this information from win32.hlp: "GetDateFormat".
i'm afraid this doesn't answer your question.
but maybe it's a hint that helps you a little bit.
have a nice day,
Black Death.