ASP 3.0 Advanced Programming (17)

Source: Internet
Author: User
Tags object definition file system html page object model string version access
Programming | Advanced 5th Chapter Script Runtime Library objects
The previous chapters have described how ASPs can use instances of objects defined on the server, leveraging the methods and properties provided to extend the performance of the ASP. There are a range of objects to use, including script objects and standard iis/asp installed components, and objects that you create or purchase from other vendors. You can also download objects for free on the internet and use them on your own pages.
This chapter discusses objects that are generally referred to as "Script Runtime Libraries" (Scripting Runtime Library) provided by the ASP scripting environment. These objects are provided to code through the scripting engine being used to complete a variety of practical tasks with the ASP script.
Another component is the Active Server component (Active Server Component), which is implemented through a separate ActiveX DLL file or other file. The following chapters discuss the relevant content.
Of course, you need to look at how to use these objects on a page. In the previous chapter, we have learned how the server provides a way to instantiate an object, which is discussed in depth in this chapter.
This chapter describes the following:
· What the scripting engine provides as a scripting object.
· How to create a script object and other component instances.
· A summary of the members and properties of the script object.
· How to use script objects in your code.
Let's start by studying the definition of the Script object.

5.1 Definition of Script object
The ASP object model is studied in the previous chapters.
Object model is a basic means to understand the relationship between parts of a system.
The ASP object model provides a structure for manipulating HTTP requests, responses, and different elements in an ASP environment as a whole. For example, we've seen how to get any cookie value from the browser by looking at the cookie collection for the ASP Request object.
The scripting language we use also has an object model. However, this object model provided by the scripting language differs from the object model provided directly by the ASP DLL, which is provided by the Microsoft Script Runtime Library (scrrun.dll) when the default Active Scripting script engine is installed. The Microsoft Script Runtime Library is also installed.

5.1.1 Different types of objects and components
Don't be confused by the two nouns "objects" and "components," which, in a range, can be part of an ASP, and can also be accessed through COM. Conceptually, they can be grouped into four categories:
· ASP built-in objects, such as ObjectContext, Request, Response, Application, session, server, and ASPError. These are studied in chapters 2nd through 4th of this book.
· The Script object. Used by script runtime libraries, such as dictionary, filesystem, and TextStream. This is the object to be discussed in this chapter.
· The components that can be installed. Provided by Microsoft in the IIS 5.0 and ASP 3.0 standard installations. This will be discussed in the next chapter.
· Other components. Components purchased from other independent vendors, found on the Web site, or created by themselves. There are other components that are provided by Windows services or products, such as Windows Scripting Host. The corresponding list is provided in the appendix of this book, which contains a section on how to build your own components.

5.1.2 VBScript and JScript script objects
As part of the Script Runtime Library, Microsoft provides three main objects:
· The Dictionary object provides an extremely useful storage object that is used to store values, accessed and referenced by the object's name rather than its index. For example, this is appropriate for storing name/value pairs that are retrieved from the ASP Request object.
· The FileSystemObject object provides access to the server's underlying file system (IE 5.0 on the client, used in conjunction with a special type of page called "Hypertext Application (HTA)"). You can use the FileSystemObject object to traverse your computer's local and network drives, folders, and files.
· The TextStream object provides access to files stored on disk and is used in conjunction with FileSystemObject objects. TextStream objects can read or write text (sequential) files and can only be instantiated through FileSystemObject objects, so it is often assumed that TextStream objects are child objects of FileSystemObject objects.
The FileSystemObject object is the "parent" of a series of other objects and collections that are used to interact with the file system. This object provides three collections of objects: The drives, folders, and files collections, each of which is a collection of corresponding drive, folder, and file objects. They are used to traverse and locate drives, folders (directories), and files on disk. The relationships between objects are as shown in Figure 5-1:

Figure 5-1 Relationship between objects in the Script Runtime library
Below, the objects and collections are described in turn, and how they are used. However, you first need to understand the differences between object instances and the way components are created or instantiated. This is the main part of the next section.

5.2 Creating an Object Raw component instance
Creating an instance of a script Run-time library object is exactly the same as instantiating any other object and component. You can use the CreateObject method provided by the ASP server object (make sure that the object is created within the context of the current page), or use a <OBJECT> element. We're going to look at both approaches, and the way we do that depends on the needs of the page.

5.2.1 Use Server.CreateObject method
As you can see in the study of the server object, components or other object instances are created according to their ProgID:
<%
Dim Objthis
Set objthis = Server.CreateObject ("ADODB. Connection ")
%>
The ProgID string "formal" format is "vendor. Component. Version", and the vendor's name and version are optional. Typically, the ProgID contains only the first two parts (as in the previous example). A few vendors set the version number in ProgID, which avoids using the same ProgID for newer, backward-compatible versions, which requires changing the ASP page to use the new version.

5.2.2 Use <OBJECT> elements
You can use the standard html<object> element to create a component instance on the server by adding the runat parameter and specifying its value as "server." In addition, it is usually a classid that provides an object's ProgID string instead of a number:
<object id= "Objthis" runat= "SERVER" progid= "This.object" >
<param name= "param1" value= "value1" >
<param name= "param2" value= "value2" >
</OBJECT>
If the object in the script above has the appropriate properties to use in the script, the <OBJECT> element can be set through the <PARAM> element, as it usually does in an HTML page. The CodeBase property is not required when using the <OBJECT> element in ASP, and the server does not attempt to download and install objects or components when it is not available.
1. Specify a ClassID
Alternatively, you can specify the ClassID of the object or component you want to create. This is useful when you do not know what other components are installed on the target machine. For example, when instantiating a component on the page of a browser on the client.
In theory, the ProgID (text "Vendor. Component") of a component should not conflict with each other and should be unique. However, this is not unassailable. It is possible that a supplier in the north of the United States has the same name as a supplier on a Greek island. However, when you use ClassID to recognize access, the same name does not occur because ClassID is unique.
If you decide to use the ClassID of an object or component, you should put it in the ClassID property instead of the ProgID property. Such as:
<object id= "Objthis" runat= "SERVER"
Classid= "CLSID:892D6DA7-E0F9-11D2-B2E9-00105A42AF30" >
<param name= "param1" value= "value1" >
<param name= "param2" value= "value2" >
</OBJECT>
However, when instantiating objects on your own server, you should know how objects and components are installed. This makes it safe to use ProgID when creating an object instance in ASP code. This is why ClassID is rarely used within an ASP page. However, because ProgID is used to find ClassID, the classid of a component or object can be substituted for ProgID if you wish.
2. Set the scope of an object instance
By default, objects created in all ASP pages and component instances (either with Server.CreateObject methods or <OBJECT> elements) have scopes within the page (page scope). This means that the object and component only have that page in a



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.