【VB6】VB6类库项目中Instancing属性

前端之家收集整理的这篇文章主要介绍了【VB6】VB6类库项目中Instancing属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

来源页面

https://msdn.microsoft.com/en-us/library/aa234184(v=vs.60).aspx

引用内容如下:


Visual Basic Reference

Visual Studio 6.0

Instancing Property

See Also Example Applies To

Sets a value that specifies whether you can create instances of a public class outside a project,and if so,how it will behave. Not available atrun time.

Settings

TheInstancingproperty has these settings:

Setting Description
1 (Default) Private. Other applications arent allowed access to type library information about the class,and cannot create instances of it. Private objects are only for use within your component.

The Instancing property default varies depending on the project type. Private is the default only for class modules in Standard Exe projects.

When you insert a new class module into an ActiveX Exe project or an ActiveX DLL project,the default value of the Instancing property is MultiUse. When you insert a new class module into an ActiveX Control project,the default value of the Instancing property is PublicNotCreatable.

2 PublicNotCreatable. Other applications can use objects of this class only if your component creates the objects first. Other applications cannot use theCreateObjectfunction or theNewoperator to create objects from the class.
3 SingleUse. Allows other applications to create objects from the class,but every object of this class that a client creates starts a new instance of your component. Not allowed in ActiveX DLL projects.
4 GlobalSingleUse. Similar to SingleUse,except that properties and methods of the class can be invoked as if they were simply global functions. Not allowed in ActiveX DLL projects.
5 MultiUse. Allows other applications to create objects from the class. One instance of your component can provide any number of objects created in this fashion.
6 GlobalMultiUse. Similar to MultiUse,with one addition: properties and methods of the class can be invoked as if they were simply global functions. Its not necessary to explicitly create an instance of the class first,because one will automatically be created.

Setting
Applies to Project Type
ActiveX Exe ActiveX DLL ActiveX Control Std. Exe
Private X X
PublicNotCreatable
SingleUse GlobalSingleUse MultiUse GlobalMultiUse

Remarks

TheInstancingproperty applies to Class modules and was expanded in Visual Basic 5.0 to incorporate the functionality of the Visual Basic 4.0Publicproperty.

When a class is creatable,you can use any of the following techniques to create instances of the class from other applications:

  • Use theCreateObjectfunction,as in:
    Set MyInstance = CreateObject("MyProject.MyClass")
  • Use theDimstatement within the same project (or outside the project if thePublicproperty is also set toTrue),as in:
    Dim MyInstance As New MyClass

    TheNewkeyword indicates that MyInstance is to be declared as a new instance of MyClass.

If thePublicproperty isFalse,the setting of theInstancingproperty is ignored. You can always create instances of the class within the project that defines the class. If thePublicproperty isTrue,the class is visible and therefore can be controlled by other applications once an instance of the class exists.

NoteThe properties and methods of a GlobalMultiUse object are not part of the global name space of the component that provides the object. For example,within the project that contains the GlobalUtility class module,you must explicitly create an instance of GlobalUtility in order to use the object's properties and methods. Other limitations of global objects are listed in "Global Objects and Code Libraries," in "Building Code Components" in theComponent Tools Guide.

原文链接:https://www.f2er.com/vb/257131.html

猜你在找的VB相关文章