Create a new object using the text name of the class

后端 未结 5 1612
刺人心
刺人心 2020-12-06 07:00

Is there a way to set an object to the new instance of a class by using the text name of the class?

I will have a library of classes, and depending on some other var

5条回答
  •  鱼传尺愫
    2020-12-06 07:34

    VB class definitions are really defining COM interfaces behind the scenes, so one can define data types as an abstract interface definition with concrete implementations using the implements keyword.

    To get any sort of polymorphism you have to do this, otherwise you will have problems with casting. It is somewhat fiddly but technically possible to do this with VB. If you want to dig into it find some of the advanced VB books by Dan Appleman or Matthew Kurland. I'm not sure if they're still in print but they're probably available through Amazon Marketplace.

    This works with VB6 and I'm fairly sure it works with VBA.

提交回复
热议问题