howardpc,
1) I am well aware of the effects of index out-of-bound and -1 value, but that's not the issue.
2) I've tried your code (after adding the missing "Form1.ListBox1.Items.Clear;")
but without success.
3) Here is a little bit of context:
I'm trying to handle a small set of lists/menus in a conceptually very common hierarchical tree-like structure, by controlling a set of external indexes/identifiers and using just one Form and one ListBox to display the content of one list/menu at a time. It is the sole form, created once and always visible.
This implies that I need to control the ListBox entry index for "this level" list/menu upon return from a "sub-level" list/menu.
I'm using one event handler, OnKeyDown in the ListBox, to parse 3 virtuals keys,
VK_ESCAPE to terminate the application;
VK_PRIOR to determine the parameters to be fed to the Display_List procedure in order to return to the "upper level" list/menu;
VK_RETURN to display a "sub-level" list/menu determined by the currently indexed
string as an identifier, and fed to the Display_List procedure (with an entry index of zero).
I hope that this clarifies what I want to achieve with a minimalist code.