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.9k stars 298 forks source link

Late bound class instances #1174

Open ThunderFrame opened 8 years ago

ThunderFrame commented 8 years ago

VBA doesn't have a way of creating an instance of a local class, by name, but there are approaches that I've seen used...

http://stackoverflow.com/questions/1057670/vba-create-a-new-object-using-the-text-name-of-the-class

And

http://www.codeproject.com/Articles/164036/Reflection-in-VBA-a-CreateObject-function-for-VBA

Should Rubberduck attenpt to recognise this approach? Provide inspections for it?

retailcoder commented 8 years ago

@ThunderFrame can you elaborate on what the specific issue is, and what Rubberduck could do to help?

ThunderFrame commented 8 years ago

I guess I'm saying that the approach above is using:

Set obj = Application.Run("CreateMyClass")

RubberDuck might inspect that and warn that Function CreateMyClass is declared but never used.

So, Application.Run is being used to call code abstractly. The inspector should perhaps recognise that Application.Run might call code within the current project, but better still would be RubberDuck recognising the design pattern.

The latter case is hard, just like the edge cases of CreateObject with a constant as the argument.

retailcoder commented 8 years ago

That would require treating string literals as potential identifier references. One way to do this without scanning every single string literal could be to special-case references to Application.Run and then evaluate the member call's argsList - not a simple deed!

I like the idea, but this would be for 3.x or beyond.