procedure InitIni;
begin
  chkCustomColor.checked:=GetSettingInt('CustomColor',0)=1;
  edtColor.text:=GetSetting('Color','$C08080');
  shpColor.Color:=StrToColor(edtColor.text,$C08080);
  shpColor.ColorTo:=shpColor.Color;
end;

procedure SaveIni;
begin
  if chkCustomColor.checked then SetSetting('CustomColor',1)
    else SetSetting('CustomColor',0);
  SetSetting('Color',edtColor.text);
end;

procedure OnSettingInit;
begin
  BeginUpdate;
  edtColor.OnChange:='OnEditChange';
  shpColor.OnClick:='OnshpColorClick';
  shpColor.cursor:=-21; //crHandPoint
  InitIni;
  EndUpdate;
end;

//--- Widget设置窗口关闭事件，当按下设置窗口的确定按钮时会触发此事件 ---
//通过设置返回值来改变是否允许确认,当result为False时不关闭设置窗口
function OnSettingClose(iResult);
begin
  result:=true;
  SaveIni;
end;

procedure OnEditChange(sender);
begin
  BeginUpdate;
  shpColor.Color:=StrToColor(edtColor.text,$C08080);
  shpColor.ColorTo:=shpColor.Color;
  EndUpdate;
end;

procedure OnshpColorClick(sender);
var
  dlgColor:TColorDialog;
begin
  dlgColor:=TColorDialog.create(WidgetSetting);
  try
    dlgColor.Color:=shpColor.Color;
    if dlgColor.Execute then
    begin
		  BeginUpdate;
      shpColor.Color:=dlgColor.Color;
  		shpColor.ColorTo:=shpColor.Color;
  		edtColor.text:=ColorToHtmlStr(shpColor.Color);
		  EndUpdate;
   end;
  finally
    dlgColor.free;
  end;
end;
