Back to Devexpress

CalculateCheckStates(TcxEditValue,IcxCheckItems,TcxCheckStatesValueFormat,TcxCheckStates) Method

vcl-cxcheckbox-dot-calculatecheckstates-x28-851dae64-x29.md

latest4.0 KB
Original Source

CalculateCheckStates(TcxEditValue,IcxCheckItems,TcxCheckStatesValueFormat,TcxCheckStates) Method

Calculates check box states for the specified edit value.

Declaration

delphi
function CalculateCheckStates(const AValue: TcxEditValue; AItems: IcxCheckItems; AValueFormat: TcxCheckStatesValueFormat; var ACheckStates: TcxCheckStates): Boolean;

Parameters

NameTypeDescription
AValueTcxEditValue

The source edit value.

| | AItems | IcxCheckItems |

Check box items of the source editor with multiple check boxes, for example, the Properties.Items property of a TcxCheckGroup editor.

| | AValueFormat | TcxCheckStatesValueFormat |

The check box state value format.

This parameter value specifies how the function interprets source edit value (AValue) and check box items (AItems).

| | ACheckStates | TcxCheckStates |

This var parameter returns the calculated array of check box states.

|

Returns

TypeDescription
Boolean

True if the check box state calculation is successful; otherwise, False.

|

Remarks

You can call CalculateCheckStates and CalculateCheckStatesValue global functions to convert a combination of individual check box states into an edit value and vice versa. These operations can be useful for scenarios that involve interaction between editors with multiple check boxes (such as check groups and check combo boxes) and dataset fields.

Code Example: Read All Check Combo Box States

The following code example uses the TcxCustomCheckComboBox.Value property value to list all checked/unchecked item states in a TcxMemo editor:

delphi
uses
   cxCheckBox, // Declares the CalculateCheckStates global function
   cxCheckComboBox; // Declares the TcxCheckComboBox class and related types
//...

procedure TMyForm.cxButton1Click(Sender: TObject);
var
  AProperties: TcxCheckComboBoxProperties;
  AValue: Variant;
  ACheckStates: TcxCheckStates;
  I: Integer;
begin
  AValue := cxCheckComboBox1.Value;
  AProperties := cxCheckComboBox1.Properties;
  CalculateCheckStates(AValue, AProperties.Items, AProperties.EditValueFormat, ACheckStates);
  cxMemo1.Clear;
  for I := 0 to Length(ACheckStates) - 1 do
    if ACheckStates[I] = cbsChecked then
      cxMemo1.Lines.Add('Checked');
    else
      cxMemo1.Lines.Add('Unchecked');
end;
cpp
#include "cxCheckBox.hpp" // Declares the CalculateCheckStates global function
#include "cxCheckComboBox.hpp" // Declares the TcxCheckComboBox class and related types

// Add the following linker directives to the corresponding CPP source file:
#pragma link "cxCheckBox" // Required to use cxCheckBox.hpp declarations
#pragma link "cxCheckComboBox" // Required to use cxCheckComboBox.hpp declarations
//...

void __fastcall TMyForm::cxButton1Click(Sender: TObject)
{
  TcxCheckComboBoxProperties *AProperties;
  TcxCheckStates ACheckStates;
  Variant AValue = cxCheckComboBox1->Value;
  AProperties = cxCheckComboBox->Properties;
  CalculateCheckStates(AValue, interface_cast<IcxCheckItems>(AProperties->Items),
     AProperties->EditValueFormat, ACheckStates);
  cxMemo1->Clear();
  for(int i = 0; i < ACheckStates.Length - 1; i++)
  {
  if(ACheckStates[i] == cbsChecked)
    cxMemo1->Lines->Add("Checked");
  else
    cxMemo1->Lines->Add("Unchecked");
  }
}

See Also

CalculateCheckStatesValue Global Function

cxCheckBox Unit