rubberduck-vba / Rubberduck

Every programmer needs a rubberduck. COM add-in for the VBA & VB6 IDE (VBE).
https://rubberduckvba.com
GNU General Public License v3.0
1.92k stars 302 forks source link

VB6 project events not working #4046

Closed mansellan closed 6 years ago

mansellan commented 6 years ago

Several project-level events (Project load \ unload etc) not functional in VB6.

mansellan commented 6 years ago

I've done some more investigation on this. Events from VBProjects and VBComponents are being correctly raised and processed. However, this is not obvious for two reasons:

  1. The VB6 VBProject OM does not have a Mode property to expose whether the IDE is in Run, Break or Design mode. To work around this, for VB6 we call the EbMode function in vba6.dll. This works for installed instances of RD, however when running from source it incorrectly returns the mode as 'Run'. It's possible it's conflating the VB6 IDE mode with that of the C# IDE.
  2. Unlike VBA hosts, VBProjects does not raise the ProjectAdded event when the RD is first loaded (looks to be a timing issue). This means that RD does not do an initial parse when the IDE is opened on a new project. As events are short-circuited prior to first-parse, any project or component events before manually invoking a parse are missed.

The good news is that this means this issue has-workaround (be aware that events won't work when running RD from source, and for installed RD make sure the very first thing done after loading RD is to request a parse).

Needless to say, neither are very satisfying...

For sub-issue 1, the easiest fix is to reinstate the original 'dirty hack' of checking the VB6 IDE caption to detect the mode. Perhaps in an if-debug construct to limit it to debug builds.

For sub-issue 2, I need to find a way of forcing a parse on first load. The cleanest way is likely to check at startup for project(s), and manually fire the ProjectAdded event.

mansellan commented 6 years ago

OK - following SE chat I'm not going to pursue a fix for point 2 - there's no way to reliably parse on first open where projects load before RD does. Besides, it's not too onerous to require a parse before RD events become active.

Looks like I was wrong on point 1 - I can't get EbMode working at all now, it may have been a short-circuited build that was running when I though I saw it working.

So for now I'm going to go back to querying the main window caption. Not elegant, but it does seem to be fairly reliable.