随笔-22  评论-7  文章-0  trackbacks-0

环境WindowsXP,BCB6.0(UPD4 (English)
Form1(主Form),Form1上有Button1,点击Button1显示Form2。
Form2上有一个RadioGroup1和Edit1,在Form2的OnShow事件中,
进行RadioGroup1->ItemIndex = StrToInt(Edit1->Text);赋值操作。Edit1->Text默认值0。
Form2显示后,在界面上选择与StrToInt(Edit1->Text)不同的选项后关闭Form2。假设选择了第二项。
回到Form1,重新打开Form2,这时应该显示的是RadioGroup1->ItemIndex = 0;
可是结果却显示为第二项。


PS:Form1,Form2都是自动创建的Form。

From1.cpp代码如下
//----------------------------Head Begin-----------------------------------------------
#ifndef Unit1H
#define Unit1H
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
        TButton *Button1;
        void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public:  // User declarations
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
//---------------------------Head End------------------------------------------------


//---------------------------Cpp Begin------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    Form2->Show();
}
//--------------------------Cpp End-------------------------------------------------


Form2代码如下
//--------------------------Form2  Head Begin-------------------------------------------------

#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published: // IDE-managed Components
    TRadioGroup *RadioGroup1;
    TEdit *Edit1;
    void __fastcall FormShow(TObject *Sender);
private: // User declarations
public:  // User declarations
    __fastcall TForm2(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//---------------------------------------------------------------------------
#endif
//-----------------------------Form2 Head End----------------------------------------------


//-----------------------------From2 Cpp Begin----------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm2::FormShow(TObject *Sender)
{
    RadioGroup1->ItemIndex = StrToInt(Edit1->Text);

}
//------------------------------From2 Cpp End---------------------------------------------


解决方法:
在TForm2::FormShow加入RadioGroup1->SetFocus(); 

void __fastcall TForm2::FormShow(TObject *Sender)
{
    RadioGroup1->SetFocus(); //加入
    RadioGroup1->ItemIndex = StrToInt(Edit1->Text);

}

posted on 2010-07-05 15:53 楚天清秋 阅读(1697) 评论(1)  编辑 收藏 引用 所属分类: C++ Builder

评论:
# re: BCB的RadioGroup控件的ItemIndex属性BUG! 2011-01-23 11:23 | 人渣
用showmod.. 显示模式对话框看看。
要是还不行,就用hide,不用close。
似乎也见过。  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理