我现在需要做一个Combo Ctrl,需要列举出所有的时区。就像系统Date and Time Properties对话框中的Timezone中的那个Combo Ctrl一样。
如果不能实现的话,我就只能hard code所有的时区了,这样太痛苦了。

解决方案 »

  1.   

    procedure TfrmDateTime.GetKeyValues;
    const
      MasterKey='\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones';
    var
      ARegistry:TRegistry;
      SubKeys:TStrings;
      i:Integer;
    begin
      ARegistry:=TRegistry.Create;
      ARegistry.RootKey:=HKEY_LOCAL_MACHINE;
      if not ARegistry.OpenKeyReadOnly(MasterKey) then exit;
      SubKeys:=TStringList.Create;
      ARegistry.GetKeyNames(SubKeys);
      ARegistry.CloseKey;
      SubKeys.Free;
      ARegistry.Free;
    end;
      

  2.   

    在9x是放在 HKEY_LOCAL_MACHINE \Software\Microsoft\Window s\CurrentVersion\Time Zones底下而在NT是放在 HKEY_LOCAL_MACHINE \Software\Microsoft\Window s NT\CurrentVersion\Time Zones底下
     
    取得这些键值后就可以通过GetTimeZoneInformation,SetTimeZoneInformation来取得并设定时区