chenzero
2008-05-24 21:09:07 UTC
Hi,
I have a application that, a combobox on it, I want to associate
each items in the combobox with an index in other data.
however, it seemed that it can not associate -1 with the item.
the code is below,
// if -1 in the associated object, if will error in ComboBox1Change() !!!
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i;
for (i=-1;i<5;i++) {
ComboBox1->Items->AddObject(IntToStr(i), (TObject*)i);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
int ii = ComboBox1->ItemIndex;
if (ii<0) return;
TObject* p = (ComboBox1->Items->Objects[ii]);
int c = (int)p;
ShowMessage(IntToStr(c));
}
//---------------------------------------------------------------------------
Any idea? Thanks!
chenzero
I have a application that, a combobox on it, I want to associate
each items in the combobox with an index in other data.
however, it seemed that it can not associate -1 with the item.
the code is below,
// if -1 in the associated object, if will error in ComboBox1Change() !!!
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i;
for (i=-1;i<5;i++) {
ComboBox1->Items->AddObject(IntToStr(i), (TObject*)i);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
int ii = ComboBox1->ItemIndex;
if (ii<0) return;
TObject* p = (ComboBox1->Items->Objects[ii]);
int c = (int)p;
ShowMessage(IntToStr(c));
}
//---------------------------------------------------------------------------
Any idea? Thanks!
chenzero