16. november 2001 - 11:20
#2
Det kan jo ikke skade :)... selvom jeg ikke er nogen ørn til Pascal... men det kan jo være jeg kan overføre det til C++. Jeg har, siden jeg oprettede spg., fået at vide at oplysningerne (selvfølgelig) findes i registreringsdatabasen... derfor kan jeg nok, hvis ikke der findes en smartere måde, hente oplysningerne derfra...
16. november 2001 - 11:29
#4
DER ER MEGET KODE !!!
Men du kan bruge det til at se hvor i Reg. du kan læse diverse oplysninger
type
TRegTimeZoneInfo = packed record
Bias: Longint;
StandardBias: Longint;
DaylightBias: Longint;
StandardDate: TSystemTime;
DaylightDate: TSystemTime;
end;
TTimeZone = class(TPersistent)
private
FStdBias: integer;
FDayBias: integer;
FBias: integer;
FDisp: string;
FStd: string;
FDayStart: TDatetime;
FStdStart: TDatetime;
FDay: string;
FMap: string;
public
procedure GetInfo;
procedure Report(var sl :TStringList);
property MapID: string read FMap;
published
property DisplayName: string read FDisp {$IFNDEF D6PLUS} write FDisp {$ENDIF} stored False;
property StandardName: string read FStd {$IFNDEF D6PLUS} write FStd {$ENDIF} stored False;
property DaylightName: string read FDay {$IFNDEF D6PLUS} write FDay {$ENDIF} stored False;
property DaylightStart: TDatetime read FDayStart {$IFNDEF D6PLUS} write FDayStart {$ENDIF} stored False;
property StandardStart: TDatetime read FStdStart {$IFNDEF D6PLUS} write FStdStart {$ENDIF} stored False;
property Bias: integer read FBias {$IFNDEF D6PLUS} write FBias {$ENDIF} stored False;
property DaylightBias: integer read FDayBias {$IFNDEF D6PLUS} write FDayBias {$ENDIF} stored False;
property StandardBias: integer read FStdBias {$IFNDEF D6PLUS} write FStdBias {$ENDIF} stored False;
end;
function CompareSysTime(st1, st2: TSystemTime): integer;
begin
if st1.wYear<st2.wYear then
Result:=-1
else
if st1.wYear>st2.wYear then
Result:=1
else
if st1.wMonth<st2.wMonth then
Result:=-1
else
if st1.wMonth>st2.wMonth then
Result:=1
else
if st1.wDayOfWeek<st2.wDayOfWeek then
Result:=-1
else
if st1.wDayOfWeek>st2.wDayOfWeek then
Result:=1
else
if st1.wDay<st2.wDay then
Result:=-1
else
if st1.wDay>st2.wDay then
Result:=1
else
if st1.wHour<st2.wHour then
Result:=-1
else
if st1.wHour>st2.wHour then
Result:=1
else
if st1.wMinute<st2.wMinute then
Result:=-1
else
if st1.wMinute>st2.wMinute then
Result:=1
else
if st1.wSecond<st2.wSecond then
Result:=-1
else
if st1.wSecond>st2.wSecond then
Result:=1
else
if st1.wMilliseconds<st2.wMilliseconds then
Result:=-1
else
if st1.wMilliseconds>st2.wMilliseconds then
Result:=1
else
Result:=0;
end;
function IsEqualTZ(tz1, tz2: TTimeZoneInformation): boolean;
begin
Result:=(tz1.Bias=tz2.Bias) and(tz1.StandardBias=tz2.StandardBias) and (tz1.DaylightBias=tz2.DaylightBias) and
(CompareSysTime(tz1.StandardDate,tz2.StandardDate)=0) and (CompareSysTime(tz1.DaylightDate,tz2.DaylightDate)=0) and
(WideCharToString(tz1.StandardName)=WideCharToString(tz2.StandardName)) and (WideCharToString(tz1.DaylightName)=WideCharToString(tz2.DaylightName));
end;
function DaysInMonth(const AValue: TDateTime): Word;
var
y,m,d: Word;
begin
DecodeDate(AValue,y,m,d);
case m of
2:
if IsLeapYear(y) then
Result:=29
else
Result:=28;
4, 6, 9, 11:
Result:=30;
else
Result := 31;
end;
end;
function EncodeDayOfWeekInMonth(const AYear, AMonth, ANthDayOfWeek, ADayOfWeek: Word): TDateTime;
var
days: integer;
day : integer;
begin
if (ANthDayOfWeek>=1) and (ANthDayOfWeek<=4) then
begin
day:=DayOfWeek(EncodeDate(AYear,AMonth,1));
day:=1+ADayOfWeek-day;
if day<=0 then
Inc(day,7);
day:=day+7*(ANthDayOfWeek-1);
Result:=EncodeDate(AYear,AMonth,day);
end
else if ANthDayOfWeek=5 then
begin
days:=DaysInMonth(EncodeDate(AYear,AMonth,1));
day:=DayOfWeek(EncodeDate(AYear,AMonth,days));
day:=days+(ADayOfWeek-day);
if day > days then
Dec(day,7);
Result:=EncodeDate(AYear,AMonth,day);
end
else
Result:=0;
end;
function DSTDate2Date(dstDate: TSystemTime; year: word): TDateTime;
begin
if dstDate.wMonth=0 then
Result:=0
else
if dstDate.wYear=0 then
Result:=EncodeDayOfWeekInMonth(year,dstDate.wMonth,dstDate.wDay,dstDate.wDayOfWeek+1)+ EncodeTime(dstDate.wHour,dstDate.wMinute,dstDate.wSecond,dstDate.wMilliseconds)
else
Result:=SystemTimeToDateTime(dstDate);
end;
function GetTZDaylightSavingInfoForYear(TZ: TTimeZoneInformation; year: word; var DaylightDate, StandardDate: TDateTime; var DaylightBias, StandardBias: longint): boolean;
begin
Result:=false;
try
if (TZ.DaylightDate.wMonth <> 0) and (TZ.StandardDate.wMonth <> 0) then
begin
DaylightDate:=DSTDate2Date(TZ.DaylightDate,year);
StandardDate:=DSTDate2Date(TZ.StandardDate,year);
DaylightBias:=TZ.Bias+TZ.DaylightBias;
StandardBias:=TZ.Bias+TZ.StandardBias;
Result:=true;
end;
except
end;
end;
procedure TTimeZone.GetInfo;
var
TZKey: string;
RTZ: TRegTimeZoneInfo;
HomeTZ, RegTZ: TTimeZoneInformation;
y,m,d,i: Word;
sl: TStringList;
const
rkNTTimeZones = {HKEY_LOCAL_MACHINE\\}\'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\';
rk9xTimeZones = {HKEY_LOCAL_MACHINE\\}\'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Time Zones\';
rkTimeZone = {HKEY_LOCAL_MACHINE\\}\'SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation\';
rvTimeZone = \'StandardName\';
begin
GetTimeZoneInformation(HomeTZ);
sl:=TStringList.Create;
with TRegistry.create do
begin
rootkey:=HKEY_LOCAL_MACHINE;
if IsNT then
TZKey:=rkNTTimeZones
else
TZKey:=rk9xTimeZones;
if OpenKey(TZKey,False) then
begin
GetKeyNames(sl);
CloseKey;
for i:=0 to sl.Count-1 do
if OpenKey(TZKey+\'\\\'+sl[i],False) then
begin
if GetDataSize(\'TZI\')=SizeOf(RTZ) then
begin
ReadBinaryData(\'TZI\',RTZ,SizeOf(RTZ));
StringToWideChar(ReadString(\'Std\'),@RegTZ.StandardName,SizeOf(RegTZ.StandardName) div SizeOf(WideChar));
StringToWideChar(ReadString(\'Dlt\'),@RegTZ.DaylightName,SizeOf(RegTZ.DaylightName) div SizeOf(WideChar));
RegTZ.Bias:=RTZ.Bias;
RegTZ.StandardBias:=RTZ.StandardBias;
RegTZ.DaylightBias:=RTZ.DaylightBias;
RegTZ.StandardDate:=RTZ.StandardDate;
RegTZ.DaylightDate:=RTZ.DaylightDate;
if IsEqualTZ(HomeTZ,RegTZ) then
begin
FDisp:=ReadString(\'Display\');
try
FMap:=ReadString(\'MapID\');
except
FMap:=\'\';
end;
Break;
end;
end;
CloseKey;
end;
end;
Free;
end;
FBias:=HomeTZ.Bias;
FStd:=HomeTZ.StandardName;
FDay:=HomeTZ.DaylightName;
DecodeDate(Date,y,m,d);
GetTZDaylightSavingInfoForYear(HomeTZ,y,FDayStart,FStdStart,FDayBias,FStdBias);
sl.Free;
end;
procedure TTimeZone.Report(var sl: TStringList);
begin
with sl do begin
Add(\'[Time Zone]\');
Add(Format(\'TimeZone=%s\',[DisplayName]));
Add(Format(\'StdName=%s\',[DateTimeToStr(StandardStart)]));
Add(Format(\'StdBias=%d\',[StandardBias]));
Add(Format(\'DlghtName=%s\',[DateTimeToStr(DaylightStart)]));
Add(Format(\'DlghtBias=%d\',[DaylightBias]));
end;
end;
Jens B