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

时间:2016-02-23 07:27:51

标签: delphi devexpress delphi-xe delphi-xe7

任何人都可以帮助我如何转换为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;

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

参见下面的代码;我假设您希望包含复选框状态可能为cbsGrayed的可能性(我在StringStream中用空格字符表示。

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;