I am developing a project that has many class types, all derived from a common base class. I want to be able to, on the fly, create objects of these classes by using some string variable to tell me which one to create.
In other words,
clsObject1, clsObject2, clsObject3 are all derived from clsObject.
I read from a file, "Object1" and "Object3".
I want to be able to Dim Object as new clsObject1 Object2 as new clsObject3, simply because that's what the file said to do.
The problem is there will be so many clsObjects, with more being added later, so I don't want to have a switch that checks for each object manually. I want this to be easily expanded, using some variable within clsObject to tell me which one to create.
My idea is to create a copy of each of these objects, place them in a Collection with the string key, and dim a new object as the same type as whatever comes out of the Collection by the key.
Is there a way to do this?
Is this post confusing as heck? I'm having a hard time expressing myself here. Sorry.
In other words,
clsObject1, clsObject2, clsObject3 are all derived from clsObject.
I read from a file, "Object1" and "Object3".
I want to be able to Dim Object as new clsObject1 Object2 as new clsObject3, simply because that's what the file said to do.
The problem is there will be so many clsObjects, with more being added later, so I don't want to have a switch that checks for each object manually. I want this to be easily expanded, using some variable within clsObject to tell me which one to create.
My idea is to create a copy of each of these objects, place them in a Collection with the string key, and dim a new object as the same type as whatever comes out of the Collection by the key.
Is there a way to do this?
Is this post confusing as heck? I'm having a hard time expressing myself here. Sorry.