Well the context menu is (from what I can see) bound to the SynEdit, inside the frame, inside the Tab.
So, "TMainWindow.ActionEnvironmentExecute" is called by code in the above listed components.
When "TMainWindow.ActionEnvironmentExecute" finishes, it returns to the caller (and therefore to the PopUpMenu and the SynEdit).
I assume that CloseCurrentTab/CloseAllTab will Destroy/Free the tabsheet?
Well if you destroy the TabSheet, you also destroy all components in it...
But if inside "TMainWindow.ActionEnvironmentExecute" you destroy the PopUpMenu and SynEdit (in the tabsheet), and then you return, then the code of that PopUpmenu/SynEdit act on destroyed objects => and they will likely crash (and that crash would just be an access violation, without any explanation).
LCLRefCount catches that early, and gives an error that points to the problem. As you noticed the error says: "Maybe processing an event"
So basically you can not Destroy the TabSheet (or anything containing the calling component) in you event.
Instead you should:
- Hide it (Visible := False)
- Application.ReleaseComponent(TheTabSheet__Or__Whatever_you_want_to_free);
That will call destroy later, when it will be safe.