Не могу разобраться как считать из реестра даные часовых поясов о датах перехода на летнее/зимнее время.
Хранятся тут:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\
Параметр TZI, в reg_binary...
uses
Registry;
// Write TDateTime to Registry
procedure Reg_WriteDateTime(dwRootKey: DWord; const sKey: string; const sField: string; aDate: TDateTime);
begin
with TRegistry.Create do
try
RootKey := dwRootKey;
if OpenKey(sKey, True) then
begin
try
WriteBinaryData(sField, aDate, SizeOf(aDate));
finally
CloseKey;
end;
end;
finally
Free;
end;
end;
// Read TDateTime from Registry
function Reg_ReadDateTime(dwRootKey: DWord; const sKey: string; const sField: string) : TDateTime;
begin
Result := 0; // default Return value
with TRegistry.Create do
begin
RootKey := dwRootKey;
if OpenKey(sKey, False) then
begin
try
ReadBinaryData(sField, Result, SizeOf(Result));
finally
CloseKey;
end;
end;
Free;
end;
end;
// Example:
// Write DateTimePicker1's DateTime to Registry
procedure TForm1.Button1Click(Sender: TObject);
begin
Reg_WriteDateTime(HKEY_CURRENT_USER, 'Software\TestXYZ\','DateTime',DateTimePicker1.DateTime);
end;
// Set DateTimePicker1's DateTime from Registry
procedure TForm1.Button2Click(Sender: TObject);
var
ATime: TDateTime;
begin
ATime := Reg_ReadDateTime(HKEY_CURRENT_USER, 'Software\TestXYZ\','DateTime');
if ATime <> 0 then
DateTimePicker1.DateTime := TDateTime(ATime);
end;
procedure TForm1.Button1Click(Sender: TObject);
function title_wday(Dt: integer): string;
const
days: array[1 .. 7] of string = (
'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'
);
begin
case Dt of
1 .. 12: Result := days[Dt];
else Result := '#Err#';
end;
end;
function title_month(Dt: integer): string;
const
months: array[1 .. 12] of string = (
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
);
begin
case Dt of
1 .. 12: Result := months[Dt];
else Result := '#Err#';
end;
end;
function TZISysTimeToStr(tm: TSystemTime): string;
var
ADT: TDateTime;
sWhich: string;
begin
with tm do begin
if wMonth = 0 then Result := 'No time saved.'
else begin
ADT := EncodeTime(wHour, wMinute, wSecond, wMilliseconds);
case wDay of
1: sWhich := '1st';
2: sWhich := '2nd';
3: sWhich := '3rd';
4: sWhich := '4th';
5: sWhich := 'last';
end;
Result := Format('%s, %s %s in %s',
[TimeToStr(ADT), sWhich, title_wday(wDayOfWeek + 1), title_month(wMonth)]);
end;
end;
end;
type
TRec = record
Bias, StdBias, DltBias: Integer;
StdDate, DltDate: TSystemTime;
end;
var
Keys: TStringList;
i: integer;
var
RTZ: TRec;
Description, DisplayData: string;
DT: TDateTime;
begin
with TRegistry.Create(KEY_READ) do
try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones',false) then
begin
Keys := TStringList.Create();
try
GetKeyNames(Keys);
CloseKey;
for i := 0 to Keys.Count -1 do
begin
if OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\'+Keys[i], False) then
begin
begin
Description := ReadString('Std');
DisplayData := ReadString('Display');
ReadBinaryData('TZI',rTZ,SizeOf(RTZ)) ;
Memo1.Lines.Add(
Description + ' ' +
DisplayData + ' ' +
' Bias: ' + IntToStr(RTZ.Bias) +
' SDate: ' + TZISysTimeToStr(RTZ.StdDate) +
' SBias: ' + IntToStr(RTZ.StdBias) +
' DDate: ' + TZISysTimeToStr(RTZ.DltDate) +
' DBias: ' + IntToStr(RTZ.DltBias)
);
end;
CloseKey;
end;
end;
finally
FreeAndNil(Keys);
end;
end;
finally
Free;
end;
end;
type
_TIME_DYNAMIC_ZONE_INFORMATION = record
Bias: Longint;
StandardName: array [0..31] of WCHAR;
StandardDate: SYSTEMTIME;
StandardBias: Longint;
DaylightName: array [0..31] of WCHAR;
DaylightDate: SYSTEMTIME;
DaylightBias: Longint;
TimeZoneKeyName: array [0..127] of WCHAR;
DynamicDaylightTimeDisabled: BOOL;
end;
DYNAMIC_TIME_ZONE_INFORMATION = _TIME_DYNAMIC_ZONE_INFORMATION;
PDYNAMIC_TIME_ZONE_INFORMATION = ^DYNAMIC_TIME_ZONE_INFORMATION;
// а уж потом - твоя функция:
function GetDynamicTimeZoneInformation(
var pTimeZoneInformation: DYNAMIC_TIME_ZONE_INFORMATION): DWORD; stdcall;
external 'kernel32' name 'GetDynamicTimeZoneInformation';
type
TGetDynamicTimeZoneInformation =
function (var pTimeZoneInformation: DYNAMIC_TIME_ZONE_INFORMATION): DWORD; stdcall;
function RtlLocalTimeToSystemTime(
LocalTime: PLARGE_INTEGER;
SystemTime: PLARGE_INTEGER): NTSTATUS; stdcall;
external DLL name 'RtlLocalTimeToSystemTime';
function RtlLocalTimeToSystemTime(
LocalTime: PLARGE_INTEGER;
SystemTime: PLARGE_INTEGER): NTSTATUS; stdcall;
external DLL name 'RtlLocalTimeToSystemTime';