首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

一个有关问题

2012-03-18 
一个问题__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner){TComboBox* comb new TComboBox(

一个问题
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
TComboBox* comb = new TComboBox(this);
//comb = new TComboBox(this);
comb->Parent = this;

comb->Align = TAlign::alLeft;
comb->DoubleBuffered = true;
comb->AutoComplete = true;

comb->AddItem("firstChoice",NULL);
comb->AddItem("SecondChoice",NULL);
comb->AddItem("thirdChoice",NULL);

comb->ItemIndex = 1;
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
MessageDlg("Selected text: " + comb->Text ,
mtInformation, TMsgDlgButtons() << mbOK, 0);
}
这是2010帮助里的一个例子,错误提示 Undefined symbol 'comb' 这里的comb是buttonclick里用的comb 为什么这里用不了呢?? 怎么弄 ???


[解决办法]
TComboBox* comb 要在外部定义,另外的函数才能调用,

C/C++ code
TForm2 *Form2;TComboBox* comb =NULL; //这里//---------------------------------------__fastcall TForm2::TForm2(TComponent* Owner)    : TForm(Owner){    comb = new TComboBox(this);    //    comb = new TComboBox(this);    comb->Parent = this;    comb->Align = TAlign::alLeft;    comb->DoubleBuffered = true;    comb->AutoComplete = true;    comb->AddItem("firstChoice",NULL);    comb->AddItem("SecondChoice",NULL);    comb->AddItem("thirdChoice",NULL);    comb->ItemIndex = 1;}//---------------------------------------void __fastcall TForm2::Button1Click(TObject *Sender){    MessageDlg("Selected text: " + comb->Text ,     mtInformation, TMsgDlgButtons() << mbOK, 0);}//--------------------------------------- 

热点排行