TAdvStringGrid GetCheckBoxState in C++

Using TAdvStringGrid GetCheckBoxState function with the bool state result in C++ on Builder XE6 gives incorrect results because the value of the bool returned is not 1 when true but greater than 1 and when compared with another bool that is true, fails.  This however, may be considered a compiler bug.  Builder XE6 apparently expects bools to be either 1 or 0.


bool __fastcall GetCheckBoxState(int ACol, int ARow, bool &state)/* overload */;


Return value of GetCheckBoxState indicates if the cell contains a checkbox or not (TRUE = contains checkbox) The actual state of the checkbox is returned via the VAR parameter state.

Yes that is understood.  The VAR parameter state is the one with problems.

The component itself is written in Delphi, as such, the event handler signature is defined in Delphi and uses a Delphi boolean and I have always known these to match C++ bools.

Try doing it yourself and then look at the state result in the debugger as (int)rstate and let me know what you get.

state is a bool and is supposed to be used as bool.


This code works as expected:

//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  AdvStringGrid1->AddCheckBox(1,1,false,false);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  bool state;
  AdvStringGrid1->GetCheckBoxState(1,1,state);

  if (state) {
Caption = "TRUE";
}
  else
  {
Caption = "FALSE";
  }
}

Try this:

//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  AdvStringGrid1->AddCheckBox(1,1,false,false);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  bool state;
  bool compare = true;
  AdvStringGrid1->GetCheckBoxState(1,1,state);

  if (state==compare) {
Caption = "TRUE";
}
  else
  {
Caption = "FALSE";
  }
}

Works as expected here on XE6 but also other C++Builder versions.

Thank you. You are right.  I see it is more complicated to reproduce.  Let me try on my end.