
//读取配置
procedure InitSetting;
var
  inifn:TIniFile;
  s:string;
begin
  BeginUpdate;
  edtTitle.text:=GetSetting('Title','自新中国建立：');
  chkLunarDate.checked:=GetSettingInt('LunarDate',0)=1;
  edtYear.text:=GetSetting('Year','1949');
  cbbMonth.ItemIndex:=GetSettingInt('Month',10)-1;
  cbbDay.ItemIndex:=GetSettingInt('Day',1)-1;
  chkShowTime.checked:=GetSettingInt('ShowTime',0)=1;
  edtTime.text:=GetSetting('Time','20:00:00');
  chkShowSec.checked:=GetSettingInt('ShowSec',0)=1;
  chkShutDown.checked:=GetSettingInt('ShutDown',0)=1;
  chkEveryDay.checked:=GetSettingInt('EveryDay',0)=1;
  lblTime.Enabled:=chkShowTime.checked;
  edtTime.Enabled:=chkShowTime.checked;
  chkShowSec.Enabled:=chkShowTime.checked;
  chkEveryDay.Enabled:=chkShowTime.checked and chkShutDown.checked;
  EndUpdate;
end;

//保存配置
procedure SaveSetting;
begin
  SetSetting('Title',edtTitle.text);
  SetSettingInt('LunarDate',chkLunarDate.checked);
  SetSetting('Year',edtYear.text);
  SetSettingInt('Month',cbbMonth.ItemIndex+1);
  SetSettingInt('Day',cbbDay.ItemIndex+1);
  SetSettingInt('ShowTime',chkShowTime.checked);
  SetSetting('Time',edtTime.text);
  SetSettingInt('ShowSec',chkShowSec.checked);
  SetSettingInt('ShutDown',chkShutDown.checked);
  SetSettingInt('EveryDay',chkEveryDay.checked);
end;

//--- Widget设置窗口初始化事件，当打开Widget设置窗口时会触发此事件 ---
procedure OnSettingInit;
begin
  chkShowTime.OnChange:='chkShowTimeChange';
  chkShutDown.OnChange:='chkShutDownChange';
  InitSetting;
end;

//--- Widget设置窗口关闭事件，当按下设置窗口的确定按钮时会触发此事件 ---
//通过设置返回值来改变是否允许确认,当result为False时不关闭设置窗口
function OnSettingClose(iResult):boolean;
var
  i:integer;
begin
  result:=false;
  try
    if trim(edtTitle.text)='' then
    begin
      showmsg('请输入计时标题！');
      exit;
    end;
    if chkShowTime.checked then
    try
      StrToTime(edtTime.text);
    except
      showmsg('无效的计时时间！');
      exit;
    end;
    SaveSetting;
    result:=true;
  except
 		
  end;
end;

procedure chkShowTimeChange(sender);
begin
  BeginUpdate;
  lblTime.Enabled:=chkShowTime.checked;
  edtTime.Enabled:=chkShowTime.checked;
  chkShowSec.Enabled:=chkShowTime.checked;
  chkEveryDay.Enabled:=chkShowTime.checked and chkShutDown.checked;
  EndUpdate;
end;

procedure chkShutDownChange(sender);
begin
  chkEveryDay.Enabled:=chkShowTime.checked and chkShutDown.checked;
end;
