I received an Access Violation during a FreeAndNil of a dynamically created TPopupMenu using AC version 6.04. I just updated to 6.22 and the code at the point of the Access Violation seems to be the same so I suspect this error is still potentially there… anyway, here is the stack order:
FreeAndNil(myPopupMenu)
TCustomerForm.Notification
TsToolBar.Notification
TsSkinableMenus.HookPopupMenu
The first thing it does in that HookPupupMenu is:
Menu.OwnerDraw := Active;
And that is where the Access Violation occured. Note: Active should be false since it is being removed.
If the timing is right on the FreeAndNil, wouldn't the parameter Menu be nil? That would explain the AV… so, if you haven't already, I think you might want to check to be sure Menu is not nil first. Or put a try-except block around all of that.
Or is there something I should do before freeing the menu?