Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: [XE7] Selecting item in ComboBox causing an exception on closing the form


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Apr 29, 2016 4:38 AM Last Post By: Yilmaz Yoru
John Murray

Posts: 12
Registered: 1/22/16
[XE7] Selecting item in ComboBox causing an exception on closing the form  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 21, 2016 9:01 AM
Perhaps I'm being stupid but I've narrowed this down to a minimal case which is as follows...

__fastcall TForm1::TForm1(TComponent* Owner) :
    TForm(Owner) {
 
    std::vector<std::string> testVector;
 
    testVector.push_back("France");
    testVector.push_back("UK1");
    testVector.push_back("UK2");
    testVector.push_back("USA");
 
 
    for(auto& a: testVector) {
        ComboBox1->Items->Add(UnicodeString(a.c_str()));
    }
    ComboBox1->ItemIndex = 0;
}


Placing the above code in the constructor for a single form with a ComboBox placed on it will as expected create a form with France, UK1, UK2 and USA listed as items in the ComboBox.
If I close the form without selecting a different item, it closes fine but if I select a different item, I'm given an access violation exception upon closing.

The call stack shows the issue in System::_IntfClear when the project is statically linked.
Can anyone give advice regarding what I'm doing wrong?
Yilmaz Yoru


Posts: 167
Registered: 1/1/03
Re: [XE7] Selecting item in ComboBox causing an exception on closing the form  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 25, 2016 2:42 PM   in response to: John Murray in response to: John Murray
John Murray wrote:
Perhaps I'm being stupid but I've narrowed this down to a minimal case which is as follows...

__fastcall TForm1::TForm1(TComponent* Owner) :
    TForm(Owner) {
 
    std::vector<std::string> testVector;
 
    testVector.push_back("France");
    testVector.push_back("UK1");
    testVector.push_back("UK2");
    testVector.push_back("USA");
 
 
    for(auto& a: testVector) {
        ComboBox1->Items->Add(UnicodeString(a.c_str()));
    }
    ComboBox1->ItemIndex = 0;
}


Placing the above code in the constructor for a single form with a ComboBox placed on it will as expected create a form with France, UK1, UK2 and USA listed as items in the ComboBox.
If I close the form without selecting a different item, it closes fine but if I select a different item, I'm given an access violation exception upon closing.

The call stack shows the issue in System::_IntfClear when the project is statically linked.
Can anyone give advice regarding what I'm doing wrong?

--

I think you try to change form components before its done. Can you move all inside to the FormShow event. To do this go to form Events double click OnShow event and add like this

bool START=true;

void __fastcall TForm1::FormShow(TObject *Sender)
{
if(START)
{
START=false;
... // add your codes here

}
}

If I were you I would use structs or linked lists instead of vectors also you can directly add from text file by using ComboBox1->Items->LoadFromFile();

also I am not sure if this is working ? Can you change this by adding Memo1 on the form so you can see results

for(auto& a: testVector) {
Memo1->Lines->Add(UnicodeString(a.c_str()));
...
}

--
Best Regards
Dr. Yilmaz Yoru
Esenja Company
John Murray

Posts: 12
Registered: 1/22/16
Re: [XE7] Selecting item in ComboBox causing an exception on closing the form  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 26, 2016 1:03 AM   in response to: Yilmaz Yoru in response to: Yilmaz Yoru
Yilmaz Yoru wrote:
John Murray wrote:
Perhaps I'm being stupid but I've narrowed this down to a minimal case which is as follows...

__fastcall TForm1::TForm1(TComponent* Owner) :
    TForm(Owner) {
 
    std::vector<std::string> testVector;
 
    testVector.push_back("France");
    testVector.push_back("UK1");
    testVector.push_back("UK2");
    testVector.push_back("USA");
 
 
    for(auto& a: testVector) {
        ComboBox1->Items->Add(UnicodeString(a.c_str()));
    }
    ComboBox1->ItemIndex = 0;
}


Placing the above code in the constructor for a single form with a ComboBox placed on it will as expected create a form with France, UK1, UK2 and USA listed as items in the ComboBox.
If I close the form without selecting a different item, it closes fine but if I select a different item, I'm given an access violation exception upon closing.

The call stack shows the issue in System::_IntfClear when the project is statically linked.
Can anyone give advice regarding what I'm doing wrong?

--

I think you try to change form components before its done. Can you move all inside to the FormShow event. To do this go to form Events double click OnShow event and add like this

If it were related to me adding items to a non-existent component, I would get an exception on starting the program, not ending it.


bool START=true;

void __fastcall TForm1::FormShow(TObject *Sender)
{
if(START)
{
START=false;
... // add your codes here

}
}

Tried both FormShow (which is definitely not what I'd want anyway unless I liked having duplicate items) and FormCreate.
Same AV exception on closing the program.

If I were you I would use structs or linked lists instead of vectors also you can directly add from text file by using ComboBox1->Items->LoadFromFile();

This is not performance critical code. There are times and places for using different STL classes. I somehow doubt that using vectors is the root cause.


also I am not sure if this is working ? Can you change this by adding Memo1 on the form so you can see results

for(auto& a: testVector) {
Memo1->Lines->Add(UnicodeString(a.c_str()));
...
}

...how is the TMemo component in ANY way related to this issue? It has something to do with component cleanup falling over and dying a horrible death when the ItemIndex has been changed during runtime via the TComboBox component itself.

Just so you know, I did add a memo to the form, changed the code to add to the memo component and it added the text just fine.
No exception upon closing either even if I changed the text.
The issue is not related to the UnicodeStrings being generated nor the use of vectors.


--
Best Regards
Dr. Yilmaz Yoru
Esenja Company
John Murray

Posts: 12
Registered: 1/22/16
Re: [XE7] Selecting item in ComboBox causing an exception on closing the form  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 26, 2016 1:12 AM   in response to: John Murray in response to: John Murray
Well, this is interesting. I've just added a button and set the ItemIndex directly through that. No exceptions upon closing.

The problem appears to be related to the dropdown list that shows when the ComboBox component is clicked.
Yilmaz Yoru


Posts: 167
Registered: 1/1/03
Re: [XE7] Selecting item in ComboBox causing an exception on closing the form  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 29, 2016 4:38 AM   in response to: John Murray in response to: John Murray
John Murray wrote:
Well, this is interesting. I've just added a button and set the ItemIndex directly through that. No exceptions upon closing.
The problem appears to be related to the dropdown list that shows when the ComboBox component is clicked.

--

Hehehe yeah i mean use Memo1 is to see results :) something like debugger output or a watchlist.

Somehow i think dropdown list is having null pointer or null , when combobox is clicked it is trying to show that null list. May be there is a problem when you set the ItemList of ComboBox.

I can't see whole codes or no simplified example here, so check your lines and orders. If you see all is right then add this as a bug to the quality center.

--
Best Regards
Yilmaz Yoru
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02