I'm quite stuck (again::)). I want to read in all records from an SQLite3 table and show them in a list (the type you can select something in). This's the example code:
The problems start to arise as soon as I want to change the 10 to the amount of records. I've got to remove the static then, which gets other parts to complain (especially either assigning a string like "test" to it, or in the return items[index] or due to the function's return type). Anybody here able to put me in the right direction? Thanks in advance.
I don't understand what the above code bit has anything to do with either SQLite3 or AGUP. I also can't understand the words below the code.
That's part of the example code from AGUP, which creates the contents of a list-box. The words underneath basically mean that it got me to fiddle 'round and 'round to get it to work. It currently got me to this:
| 1 | char *lister(int index, int *list_size) { |
| 2 | int records; |
| 3 | records = count_records(); |
| 4 | |
| 5 | int open_dbase; |
| 6 | const char *zErrMsg = 0; |
| 7 | int result; |
| 8 | sqlite3_stmt *stmt = NULL; |
| 9 | |
| 10 | char *items[records][(LENGTH + 1) * MAX_BYTES_PER_CHAR]; |
| 11 | |
| 12 | for(int i = 1; i <= records; i++) { |
| 13 | items<i>[(LENGTH + 1) * MAX_BYTES_PER_CHAR] = "Test test"; |
| 14 | cout << "Item: " << items<i>[(LENGTH + 1) * MAX_BYTES_PER_CHAR] << "\n"; |
| 15 | } |
| 16 | |
| 17 | if (index >= 0) { |
| 18 | return items[index][(LENGTH + 1) * MAX_BYTES_PER_CHAR]; |
| 19 | } |
| 20 | else { |
| 21 | index = 10; |
| 22 | *list_size = index; |
| 23 | } |
| 24 | |
| 25 | return NULL; |
| 26 | } |
It works fine, and the cout comes on, but then the whole program crashes. The function's called in this code:
| 1 | int show_dbase() { |
| 2 | int count = count_records(); |
| 3 | char sel2[count]; |
| 4 | |
| 5 | DIALOG show_dlg[] = |
| 6 | { |
| 7 | /* (dialog proc) (x) (y) (w) (h) (fg)(bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */ |
| 8 | |
| 9 | /* this element just clears the screen, therefore it should come before the others */ |
| 10 | { d_agup_clear_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }, |
| 11 | |
| 12 | // Show records |
| 13 | { d_agup_list_proc, 40, 25, 200, 150, 0, 0, 0, 0, 0, 0, (void*)lister, 0, 0 }, |
| 14 | { d_agup_push_proc, 90, 180, 100, 18, 0, 0, 0, 0, 0, 0, (void*)"Back", 0, (void*)closebutton }, |
| 15 | { d_agup_push_proc, 275, 10, 10, 18, 0, 0, 0, 0, 0, 0, (void*)"?", 0, (void*)about }, |
| 16 | |
| 17 | /* the next two elements don't draw anything */ |
| 18 | { d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }, |
| 19 | { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL } |
| 20 | }; |
| 21 | |
| 22 | set_gui(show_dlg); |
| 23 | |
| 24 | |
| 25 | return D_REDRAW; |
| 26 | |
| 27 | } |