开发者

vb6 :create object dynamically

In vb6, i can do :

set object=new class

where object is a Object and Class is a class defined in the code.

N开发者_如何学Goow, i want to do the same dynamically, i want to do something like:

set object=createobject("class")

but it fail because createobject is apparently for activex registered class and not class modules.


If you put the class in question in a separate VB6 OCX, you will be able to use createObject to create them on-the-fly.


I hope the reason you want to do this is to mimic some sort of interface-like functionality, otherwise it's probably not an ideal solution.

Anyway, you could create a method that gives back a different class depending on the string you provide.

function myClassCreatingFunction(className)
    select className

        case: "Class1"
             set myClassCreatingFunction = new Class1
             exit function

        ...

    end select
end function
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜