我在界面上动态的New了多个TbsSkinCheckListBox。每个TbsSkinCheckListBox的Tag是唯一标识。动态New的时候把事件pCheckListBoxClickCheck赋给TbsSkinCheckListBox的OnClickCheck事件。pCheckListBoxClickCheck事件如下:
void __fastcall Tfrm1::pCheckListBoxClickCheck(TObject *Sender)
{
TbsSkinCheckListBox *pCheckListBox = static_cast<TbsSkinCheckListBox *>(Sender);
bool b = pCheckListBox->Checked[pCheckListBox->ItemIndex];
...... //省略代码
}
执行到bool b = pCheckListBox->Checked[pCheckListBox->ItemIndex];报错如下:
Access violation at address 00611B86 in module 'Project1.exe'. Read of Address 00000000.若我把TbsSkinCheckListBox *pCheckListBox = static_cast<TbsSkinCheckListBox *>(Sender);
换成TCheckListBox *pCheckListBox = static_cast<TCheckListBox *>(Sender);
则不报如上错误,但是我明明选中了某个TbsSkinCheckListBox的第某个Item. b却是false.谁能解决了如上问题另给200分,谢谢!!!

解决方案 »

  1.   

    void __fastcall Tfrm1::pCheckListBoxClickCheck(TObject *Sender)
    {
        TbsSkinCheckListBox *pCheckListBox = static_cast<TbsSkinCheckListBox *>(Sender);
        if(-1 == pCheckListBox->ItemIndex) return;
        bool b = pCheckListBox->Checked[pCheckListBox->ItemIndex];
        ......        //省略代码
    }
      

  2.   

    应该判断一下所选择的item指针是否存在
      

  3.   


    如果if(-1 == pCheckListBox->ItemIndex) return;那我下面的代码不是不执行了? 
    下面要做的事情可重要啊!
      

  4.   

     那你就不要  return  ,但
    if(-1 == pCheckListBox->ItemIndex){ 
        bool b = pCheckListBox->Checked[pCheckListBox->ItemIndex]}; 
    这是必须的。
      

  5.   

    strluck:
      我现在的着急之处就在于bool b = pCheckListBox->Checked[pCheckListBox->ItemIndex]};会报错啊,看样子应该是内存溢出的问题。
    我想了一下,会不会是我的事件void __fastcall Tfrm1::pCheckListBoxClickCheck(TObject *Sender) 
    里的Sender对象传值有问题?有没有人对TbsSkinCheckListBox有比较深入的研究?关键的问题是我现在要怎么要可以取到pCheckListBox->ItemIndex而不会内存溢出。
        或者我转换成TCheckListBox *pCheckListBox = static_cast<TCheckListBox *>(Sender);。但是b = pCheckListBox->Checked[pCheckListBox->ItemIndex]; 这样不会溢出,但是跟踪b的值是false, b的值要取到true,问题就解决了! 有没有可能呢? 谢谢。