【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 at run time.

Settings

The Instancing property 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 the CreateObject function or the New operator 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 X X
PublicNotCreatable X X X  
SingleUse X      
GlobalSingleUse X      
MultiUse X X    
GlobalMultiUse X X    

Remarks

The Instancing property applies to Class modules and was expanded in Visual Basic 5.0 to incorporate the functionality of the Visual Basic 4.0Public property.

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

  • Use the CreateObject function, as in:
    Set MyInstance = CreateObject("MyProject.MyClass")
    
  • Use the Dim statement within the same project (or outside the project if the Public property is also set to True), as in:
    Dim MyInstance As New MyClass
    

    The New keyword indicates that MyInstance is to be declared as a new instance of MyClass.

If the Public property is False, the setting of the Instancing property is ignored. You can always create instances of the class within the project that defines the class. If the Public property is True, the class is visible and therefore can be controlled by other applications once an instance of the class exists.

Note   The 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 the Component Tools Guide.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章