Programming | Advanced 5.2.5 Reference Object type library
In an earlier ASP version, when an object or component was used in a script, the public constants defined within the component, if any, would no longer be valid in the ASP. This means that we need to declare them (or equivalent) ourselves and specify the corresponding values.
For example, when using an ActiveX database object (ADO) component in an earlier version of ASP (which will be studied in detail in chapter 8th), you have to add a predefined constant declaration with the recordset's Open method. For example:
Const adOpenKeyset = &h0001
Const adlockpessimistic = &h0003
Const adCmdTable = &h0002
...
Rs. Open "Contact", "dsn=globalexampledata; Uid=examples; password=; ", _
adOpenKeyset, adLockPessimistic, adCmdTable
...
Alternatively, use the #include directive to insert a file named Adovbs.inc on the page. This file is provided by iis/asp and contains all predefined constants required by ADO. When you update your code, you must confirm that you are using the latest version and check that it is available for all page requests.
For IIS 5.0, there is a better way to add references to the type library of a component or object by using the metadata directive within an HTML annotation element (IIS 4.0 does not support this feature).
<!--METADATA type= "TypeLib"
File= "Path_and_name_of_file"
Uuid= "Type_library_uuid"
verssion= "Major_version_number.minor_version_number"
Lcid= "locale_id"
-->
which
· Path_and_name_of_file is the absolute physical path of a type library file (. tlb) or an ActiveX DLL, which must either be supplied with this parameter or a type_library_uuid parameter.
· Type_library_uuid is the only unique identifier for the type library, which must either be supplied with this parameter or a path_and_name_of_file parameter.
· Major_version_number.minor_version_number (optional) defines the version of the desired component. If this version is not available, the most recent version is used.
· LOCALE_ID (optional) is an area marker. If no type library is found in this area, the computer uses the default (defined by installation) zone.
Therefore, using this technique, the built-in ADO predefined constants can be made available on an ASP page by using the following code:
<!--METADATA type= "TypeLib"
file= "C:\Program Files\Common Files\system\ado\msado15.dll"
-->
The filename Msado15.dll can also be used for later versions of the ADO component (after 2.50).
If the ASP cannot mount the type library, it returns an error and stops execution of the page. Possible error hints are shown in table 5-1:
Table 5-1 Error hint code and description
Error description
Invalid type library description for ASP 0222
Type library not found in ASP 0223
The ASP 0224 type library cannot be loaded
ASP 0225 type libraries cannot be packaged (that is, ASP cannot create type library wrapper objects from the specified type library)
5.2.6 create an object instance on the client
When discussing techniques for instantiating objects and components on a server in ASP, it is worth emphasizing the way in which the client pages are run in the browser to do the same work. This is useful if you use ASP to create a page that contains client-side scripting, or to create a client component instance using the <OBJECT> element. In most cases, the script runtime object can be instantiated and used on the client, the same effect as the ASP on the server.
1. VBScript CreateObject method
When the client uses CreateObject, a component or object instance is created within the browser's environment, which runs in the same memory space (within the process) as the browser, unless the implemented object is an executable file with the. exe extension file name.
You typically specify the ClassID of an object instead of using a ProgID string, which can not conflict with other objects installed on the client.
<script language= "VBScript" >
Dim Objthis
Set Objthis = CreateObject ("CLSID:892D6DA7-E0F9-00105A42AF30")
...
</SCRIPT>
Of course, you can use ProgID and use common objects or components (especially those provided by standard installations), so the risk of getting the wrong component is small:
<script language= "VBScript" >
Dim Objthis
Set Objthis = CreateObject ("Scripting.Dictionary")
...
</SCRIPT>
2. Jscript ActiveXObject method
In order to instantiate the objects and components of JScript on the client, you must use the ActiveXObject method and the new operator:
<script language= "JScript" >
var objmydata = new ActiveXObject (' clsid:892d6da7-e0f9-00105a42af30 ');
</SCRIPT>
Or:
<script language= "JScript" >
var objmydata = new ActiveXObject (' This.object ');
</SCRIPT>
3. <OBJECT> element Technology
You can also use the <OBJECT> element to create an instance of a client object or component. You should omit the runat attribute or set it to "CLIENT". However, this property is ignored on the client, so the sole purpose of setting this property is to prevent confusion when an ASP page instantiates a server-side component instance using the <OBJECT> element.
<object id= "Objthis" runat= "CLIENT"
Classid= "CLSID:892D6DA7-E0F9-00105A42AF30"
codebase= "Http://yourserver.com/components/mycomponent.cab" >
<param name= "param1" value= "value1" >
<param name= "param2" value= "value2" >
</OBJECT>
Note that the CODEBASE attribute appears here, indicating that the component from the URL is allowed to download and install if it is not installed. IE more than 3.0 of the version has this function.
You can view Web site http://msdn for methods that use the <OBJECT> element, properties you can use, and values that you use on the client. Microsoft.com/workshop/author/dhtml/reference/objects/object.asp, or <OBJECT> in the Windows Platform SDK documentation tags, or see "IE5 Dynamic HTML Programmer ' Reference" a book, ISBN 1-861001-74-6,wrox publishing house.
5.3 Scripting.Dictionary Object
Many Microsoft programming languages, such as Visual Basic, VBScript, and JScript, provide collections (collection). You can think of a set as an array, and you can use the built-in functions to accomplish basic tasks such as storing and manipulating data. There is no need to worry about the ranks of the data, but access using unique keys.
Both VBScript and JScript provide similar objects, commonly known as scripting.dictionary objects or Dictionary objects. It is similar to a two-dimensional array, where the data for the key and related entries are stored together. However, the real object-oriented approach should not directly access data entries, it must be implemented using the methods and properties supported by the Dictionary object.
This chapter provides sample pages that allow you to test the methods and properties of the script Runtime object. These instances are in the CHAPER05 subdirectory of the file of the downloaded file.
5.3.1 Create and use Dictionary objects