ASP CreateObject Attribute
Definition and Usage
The CreateObject method creates an instance of an object.
Note:Objects created using this method have page scope. This means that after the current ASP page is processed, the server will automatically destroy these objects. To create objects with session or application scope, you can use the <object> tag in the Global.asa file and set the SCOPE attribute to session or application, or you can store the object in the session or application variables.
Syntax
Server.CreateObject(progID)
Parameters | Description |
---|---|
progID | Required. The type of object to be created. |
Instance
Example 1
This example creates an instance of the server component MSWC.AdRotator:
<% Set adrot=Server.CreateObject("MSWC.AdRotator") %>
Example 2
When the session ends, the object stored in the session variable will be destroyed. However, you can also destroy the object by setting the variable to Nothing or a new value:
<% Session("ad")=Nothing %>
Or:
<% Session("ad")="a new value" %>
Example 3
Cannot create an object instance with the same name as a built-in object. For example, the following script will return an error:
<% Set Application=Server.CreateObject("Application") %>