Overview
If you use ASP to develop, you may already have used COM in your ASP page. However, before you develop a COM component or read a book for a detailed introduction to COM, you are likely to not fully understand COM, Therefore, it is not possible to make full use of your ASP page. At the same time, you can't understand the use documentation brought by COM components. If you know the standard and limit of COM, you can learn from other things. COM parts.
In this tutorial, we will learn how COM work, you will also learn knowledge of proficient com.
Readers of this tutorial
This tutorial will give those who have used VBScript language, especially those who have used ADO but don't know that is COM. He will tell you:
1. Difference between attributes and methods
2. Do you need a parameter attribute?
3. What is the meaning of read-only attribute?
4. What is a collection of objects?
5. What properties do every collection object?
6. Do not call how to sort a collection
7. How many COM components can be available in a DLL.
Basic knowledge
COM is a standard for an object interface. Defining a COM object only requires a definition method and attribute, no other interface. From a programmer's point of view, there is not much difference between attributes and methods. Method can with parameters, attribute No. Attributes can read and write, if you want to return the value, it is read-only.
Although the properties and methods don't have much difference from the programming perspective, the component developers use them to complete different features. The attribute usually represents an object's status, but the calling method can complete anything that wants to complete, regardless of him contains objects State or not.
Attributes
Attributes do not require parameters, used to describe or set the status of the object. All attributes return a value, some attributes are read-only, some are readable. The following is an expression example of reading attributes in VBScript:
example 1:
Value = Object.property
Note that there is no brackets here. Example 2 is to set the property example:
Example 2:
Object.property = Value
method
Methods can be used with parameters, and the value can be returned. Usually to initialize an event of an object. When the parameter is passed to the method, the method can be used to set the value. If the method only returns a value, the expression is as follows:
Example 3:
Value = Object.method ()
Note 3 in Example 3. You must use parentheses when the method is returned to the value. For example, the object consNection has an Execute to return a RECORDSET object. Example:
Example 4:
SET RS = conn.execute ("Select * from table")
Users who don't have to return values, do not have a parameter, such as a CLOSE method of the Connection object:
Example 5:
Conn.close
parameter
The method can bring one or more parameters, or one or not. However, the parameters are not required. Once a parameter is optional, the subsequent parameters are optional. For example, the parameters one and parameter two are Required, parameter three is optional, the parameter 4 must be optional. A good example is the OPEN method for the Connection object. He has eight optional parameters. The first three used to deliver the database and The information of the number. You can call the OPEN method as in Example 6:
Example 6:
Conn.open "DSN", "SA", ""
In order to provide DSN name, user name, password is empty, you can also call:
Example 7:
Conn.open "Driver = SQL Server; Server = YourServerName; UID = SomeUid;" & _
"PWD = SomePwd; Database = SomeDatabase;"
Note In Example 6, we used three parameters, in Example 7, only one, the result is the same.
When the method is called, separated by a comma, allowing the optional parameters to be empty, will pass null values to this parameter.
In Example 6, the optional parameter is used by the default value in Example 8.
Example 8:
Conn.open "DSN", "SA", "",,,
set
The collection is that it contains many objects of many objects. All collections contain some predefined methods and properties. A collection has an Item method, a count property, a _newenum method. Collection has the same type of objects Ability. In other words, if an object can be included in a collection, then,, this sentence is hard, I will not turn it out, give the original text. (In Other Words, IF a Particular Object Can Be Group in a set then that object will have a collection object that can create an instance of an object within the set. For instance, a Drives collection object will contain a set of drives that might represent all the drives on a particular computer) .Count property returns A long integer value representing the number of elements in the collection. Passing a long integer for the ITEM method (of course, between 1 and count), return the object points to this index in the collection. As an array. (In this case Discharge, slightly adjustment)
Example 9 (1):
Set Object = Collection.Item (2)
Because Item is a default method, you can also call as follows:
Example 9 (2):
Set Object = Collection (2)
_Newenum method can be called repeatedly,
Example 9:
For Each Object In Collection
Next Object
(The following is not translated)
Notice That the_newenum method is not reasoned within the syntax of the
Statement in Example 6. this is Because The _newenum Method Has A Special
Index That Visual Basic Recognizes As Being Used for the for Next Statement. as a
Little Background, All Methods and Properties In a com object area indexed and
Certain Indexes Are Used for Particular Tasks. for Example The Zero Index IS Used
For The Default Method or Property.
The Default Method or Property
The Method or Property That Has The COM Index of Zero Is Called The Default
Property. Visual Basic Allows The Programmer to Not Use the regular
Method / Property Syntax when Calling The Default Value, You Can Leave The
Syntactical Call to the method / proty off all together. for example, the default
Method in all collections is the item method. if Where Going to Call The Item
Method, You Could Do IT Like It in Example 9.
In order to create a COM object in the ASP, you can:
Example 11:
Set Object Server.createObject ("smm.xcheck.1")
Give Server's CreateObject method only passes a parameter, it is a ID value, which is given by the COM part provider, uniquely identifies a symbol of a COM object. To create an instance of a COM object, you must know the object ID value. Another way to get an object's instance, you can use an existing object instance to create a new object instance, in fact, this is working like this, you call the item method, return it. An object instance.
Example 12:
Set Object = Collection.Item (2)
Example 11 and Example 12 are the same, that is, all from other objects created objects, differences, CreateObject can create any type of object, and Item can only return objects in the collection. Just like a chicken first, or Like the problem of eggs first, you may ask, how did the Server object come? In fact, this is a built-in object. He exists in the ASP.
Built-in object
There are six built-in objects in the ASP, they are:
Server
REQUEST
Response
ObjectContext
Application
Session
These objects are unique to other objects. They do not need to create an instance. They have their own objects, they have their own methods and properties. Because they are built-in, so you don't need to know their ID, in fact, you fundamentally Do not call CreateObject to create them.
Object ID
If the main method of creating an object is to call CreateObject, you know the ID of the object is very important. The COM parts provider is the ID of the object in their document.
(The following is not translated)
The Documentation
Now That We Have Established The Undering Between Methods and Properties
Along with Their Different Attributes, We need to understand how the documentation
For The Objects Repesents these Attributes, WE Are Going to Look At
15 SECONDS 'Component Section, Which is in the Same Format As The IIS 4.0
Component Documentation.
Read and Write Properties
A Good Example of a Read / Write Property Is this of the phoneTranslate Property Of
The Xcheck Object, Shown Here in Example 11:
EXAMPLE 13
Object.phonetranslate [= value]
Notice The Value Syntax, this is The Indication of a Property That Can Be Written TO.
The Brackets Denote That The Property Is Optional, in Other Words you do not need NEED
TO SET The Property To Use the Object. Click Here to View The Full Documentation.
Read Only Properties
A Good Example of a Read Only Property Is The Expires Property of the Aspmail
Object.
EXAMPLE 14
Object.expires
Notice That Unlike Example 11 there is not an equal symbol, indicating this is read
Only. Click Here to View The Full Documentation.
Optional Method Argumentsa Good Example of The Optional Arguments Is The Sendx Method of The Ocxmail
Object. The Documentation Syntax Can Be Seen Here IN EXAMPLE 12:
EXAMPLE 12
Object.sendx (MailServer [, fromname ", fromaddress [, priority
ReturnReceipt [, toaddresslist [, ccaddresslist [, bccaddresslist [,
Attach [, MessageSubject [, Messagetext]]]]]]]]])
Notice That The Only Required Argument Is The Mail Server Argument. All the rest,
Noted by the brackets are optional. Click Here to View The Full Documentation.
Summary
WITH A Fundamental Understanding of Com and It's Abilities, Coupled with Good
Documentation you can expand the flexibility of your active server page
Programming. Take Take The Information That You Already Know About Programming IIS
Objects, Like Session Objects and ado, and expand on what by Adding More
Com objects to your repertoire. Third Party com Object Will Allow you to to YOU
Expand your Active Server Applications and Accomplish Tasks Rapidly by LeveRaging
The Component Object Model.