 const
   MB_OK=0;

//保存配置
procedure SaveSetting;
begin
  SetSettingBool('ShowLunar',chkLunar.checked);
  SetSettingBool('ShowSolar',chkSolar.checked);
  SetSettingBool('ShowOther',chkOther.checked);
  SetSettingInt('ShowDays',StrtoInt(edtDays.text));
end;

//--- Widget设置窗口初始化事件，当打开Widget设置窗口时会触发此事件 ---
procedure OnSettingInit;
begin
  Beginupdate;
  chkLunar.checked := GetSettingBool('ShowLunar',true);
  chkSolar.checked := GetSettingBool('ShowSolar',true);
  chkOther.checked := GetSettingBool('ShowOther',true);
  edtDays.text := inttostr(GetSettingInt('ShowDays',7));
  Endupdate;
end;

//--- Widget设置窗口关闭事件，当按下设置窗口的确定按钮时会触发此事件 ---
//通过设置返回值来改变是否允许确认,当result为False时不关闭设置窗口
function OnSettingClose(iResult);
var
  i:integer;
begin
  result:=true;
  try
    i:=StrToInt(edtDays.text);
    if i<0 then raise('');
		if i>365 then 
		begin
			messagebox(WidgetSetting.handle,'无效的数量！','',MB_OK);
			edtDays.text:='365';
			result:=false;
			exit;
		end;
  except 
    messagebox(WidgetSetting.handle,'无效的数量！','',MB_OK);
    result:=false;
    exit;
  end;

  SaveSetting;
end;
