And if I use Exception, or Try … Catch, along with a #Pragma BreakOnExceptions False / True block to ignore the exception, the debug app results in a hard crash.
That’s a different issue. I use .clone for on-the-fly menu items under Cocoa to avoid the problem you mention.
This is a menu item that already exists in a MenuBar, and is populated in the EnableMenuItems event. Before showing it to the user, I delete all existing items and add items from an array of strings that changes as the user works (it’s a history list).
[quote=229113:@Aaron Hunt]In the EnableMenuItems event, this code
dim j, k as integer
k = myMenu.count - 1
for j = k downto 0
myMenu.remove(j)
next
Works fine on Mac, throws an OutOfBoundsException on Windows, when j= 0. Debugger shows k is a positive value.[/quote]
Just tried that code in 2015R3.1. No error. The menu is emptied, that is all.
Is that all the code you have in EnableMenuItems ?
[quote=229497:@Aaron Hunt]There is no error in the code, and no reason it should crash. Like I said, it makes no sense.
There is code after deleting the menu items which populates the menu, but the debugger never even gets there on Windows. Everything works fine on Mac.[/quote]
Maybe you are to check with a test app with only the code you posted, as I did. No error.
What is myMenu.Count? Probably zero as well. This sounds like potential reentrancy. What does the stack look like when it crashes? Do you have any calls to DoEvents in your app?
Thank you, your while … wend code is a cleaner approach.
Something related, I just found (by putting only “beep” in the EnableMenuItems event) that the EnableMenuItems event of a window fires on Windows 7 when these keys are pressed:
Shift
Control
Alt (fires twice: on key down and key up)
That is really troubling! Can I stop that from happening?
I understand why pressing these keys would fire if the menu was open, since on Windows it means the menu text can change, but why do they fire when no menu is open? Seems like the event should fire when the assigned key + modifier is pressed, not when the modifier key is pressed by itself. I guess this has to do with how keys events are tracked.
Is there a note somewhere about this difference between Mac and Windows? Seems pretty important to know. At least, in working with key combinations it has caused me a lot of headaches in the last few hours that could have been avoided.