从 TcxCheckListBox 到 TcxCheckGroupBox(从 TStringStream 加载状态)

From TcxCheckListBox to TcxCheckGroupBox (Load States from TStringStream)

任何人都可以帮助我如何从这个转变为与 TcxCheckGroup 一起工作?我的程序可以加载检查 Items 状态到 cxCheckListBox.

工作示例 TcxCheckListBox...

procedure Tfrm.LoadStatesFromStream(SS: TStringStream);
var
  i : integer;
  S2 : String;
begin

  SS.Position := 0;
  i := 0;
while (i <= cxCheckListBox1.Items.Count - 1) and (SS.Position < SS.Size) do    
begin
  S2 := SS.ReadString(1);
  cxCheckListBox1.Items[i].Checked := S2 = '+';
  Inc(i);
end;
end;

我需要帮助...

procedure Tfrm.LoadStatesFromStream(SS: TStringStream);
var
  i : integer;
  S2 : String;
begin
  SS.Position := 0;
  i := 0;
while (i <= cxCheckGroup1.Properties.Items.Count - 1) and (SS.Position <   SS.Size) do
begin
  S2 := SS.ReadString(1);
  (cxCheckGroup1.States[i] = cbschecked ):= S2 = '+';  //I have a problem here

  Inc(i);
 end;
end;

感谢您的帮助!

见下面的代码;我假设您想包括复选框状态可能是 cbsGrayed 的可能性(我在 StringStream 中用 space 字符表示。

function CheckBoxStateToString(CheckBoxState : TcxCheckBoxState ) : String;
begin
  Result := '';
  case CheckBoxState of
    cbsChecked : Result := '+';
    cbsUnChecked : Result := '-';
    cbsGrayed : Result := ' ';
  end;
end;

function StringToCheckBoxState(Input : String) : TcxCheckBoxState;
begin
  Result := cbsGrayed;
  if Input = '+' then
    Result := cbsChecked
  else
    if Input = '-' then
      Result := cbsUnChecked
end;

procedure TForm1.SaveCheckGroupStatesToStream(SS : TStringStream);
var
  i : integer;
begin
  SS.Clear;
  SS.Position := 0;
  for i := 0 to cxCheckGroup1.Properties.Items.Count - 1 do begin
      SS.WriteString(CheckBoxStateToString(cxCheckGroup1.States[i]));
  end;
  Memo1.Lines.Add('>' + SS.DataString + '<');
end;

procedure TForm1.LoadCheckGroupStatesFromStream(SS : TStringStream);
var
  i : integer;
  S : String;
begin
  CheckBoxList.ClearCheckmarks;
  SS.Position := 0;
  i := 0;
  while (i <= cxCheckGroup1.Properties.Items.Count - 1) and (SS.Position < SS.Size) do begin
    S := SS.ReadString(1);
    cxCheckGroup1.States[i] := StringToCheckBoxState(S);
    Inc(i);
  end;
end;