一个问题
__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 要在外部定义,另外的函数才能调用,
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);}//---------------------------------------