dsk wrote:Code: Select all
void LoadCategories(wxListBox* itemListBox)
{
wxArrayString *temp;
wxSQLite3ResultSet q1 = db.ExecuteQuery("select name from categories;");
while (q1.NextRow())
{
temp->Insert(q1.GetString(0).mb_str(), 0);
}
itemListBox->InsertItems(temp, 0);
}
This is simple code, but there is error.
Definitely. Your variable
temp is an uninitialized pointer, that is, the program will crash on the first call to insert.
dsk wrote:What I need.... just I need to insert results from
wxSQLite3ResultSet class to wxArrayString... and then to listbox
First alternative (a minor modification of your code):
Code: Select all
void LoadCategories(wxListBox* itemListBox)
{
wxArrayString temp;
wxSQLite3ResultSet q1 = db.ExecuteQuery("select name from categories;");
while (q1.NextRow())
{
// Insert with nIndex as 0 reverses the order of the results
// Use temp.Add(q1.GetString(0)) to get the same order.
temp.Insert(q1.GetString(0), 0);
}
itemListBox->InsertItems(temp, 0);
}
Second alternative (directly add strings to listbox):
Code: Select all
void LoadCategories(wxListBox* itemListBox)
{
wxSQLite3ResultSet q1 = db.ExecuteQuery("select name from categories;");
while (q1.NextRow())
{
// If the last parameter of InsertItems is 0, the result order is reversed
// Increase it by 1 for each loop step to get the same order
itemListBox->InsertItems(1, &q1.GetString(0), 0);
}
}
Regards,
Ulrich