Web| Program | Component Development If you are an active Server page (ASP) developer, I believe you may often use COM objects to create ASP pages. Even when you use it, you ignore that he is a COM object. For example: ADO. The only component with the highest call rate is the ability to extend unlimited functionality to your page. However, the ASP itself is an interpretative script that is not functional enough to COM strong. As a rapid development, ease of use, support COM VB Natural as the ASP in the development of COM's primary tool. The following demonstration and description, through the Visual Basic language, tells you how to write the COM and COM object models, and I believe you will get something.
- What is the difference between a property and a method?
- Describe the main point of a property?
- What is the meaning of a read-only property?
- What is a collection object?
- What is a standard attribute in a collection object?
- ........
COM is an object-oriented standard that only methods and properties are defined in a COM object. They have no other interfaces, methods can have parameters, properties cannot, properties have read/write properties, and methods can return a value.
Property
property does not receive any parameters and is typically used to describe object state or set an object. All properties return a value, while some properties are read-only and some are read/write. Here's a visual Basic syntax example to help you interpret attributes:
Example 1
Read
Value = Object.property
Write
Object.property = value
Note: There are no familiar parentheses here, just like the variable assignment. Here is the difference from the method (Function/sub). The above is to set a property in visual Basic syntax.
Method
Method can return a value or assignment, usually by using an object initialization event, or by a Function procedure call. Method can be assigned a value, but only exists with the argument list, if a method has no arguments, then the syntax is as follows:
Example 2
Value = Object.Method ()
Note that in Example 2 this method is set to null (), and the method can have a return value that must have a band (). For example, this connection object has an execution method and returns a Recordset object. Here is an example:
Example 3
Set Rs = Conn.execute ("Select * FROM table")
method does not return a value, and there is no () in the parameter. For example, the Close method in a Connection object.
Example 4
Conn.close
Focus:
Method can get one or more parameters or do not get parameters. However, the parameters are also optional. Parameter one but exists, you must assign all values. If one argument is optional, all other parameters after the argument are equally optional. Example: the way to open a database connection is a good example of an optional parameter approach. This open method has eight optional parameters. First, the second is to establish database and login information. As Example 5
Example 5
Conn.Open "DSN", "sa", "" "
Displays a data source for a DSN, a login account for an SA, and an empty password. Or you can see the method open in Example 6:
Example 6
Conn.Open "Driver=sql server;server=yourservername;uid=someuid;" &_
"Pwd=somepwd;database=somedatabase;"
Note that in example 6 we used only one parameter and the three optional parameters we used in Example 5 were the same. An optional parameter is a parameter in a called method that allows null or has been inserted in the default value. The optional parameter used in Example 6 is the default value, and the optional parameter used in example 7 is null.
Example 7
Conn.Open "DSN", "sa", "" ",,,,
The optional parameters for the null value in Example 8 are different from those of example 5. ,
Collection
Collection objects can store many elements and can change their data after they are created. A collection has the Item method, a Count property, and a traversal method. The collection type of a collection also requires the ability to create objects. Other words. If a particular object needs to create a group of objects in a collection object. As an example, a drive collection object needs to provide detailed information about the display drive on the computer.
Returns the number of objects in this collection with the Count property. The traversal method allows the programmer to loop through a collection object from beginning to end. The traversal method is illustrated in Example 8:
Example 8
For all Object in Collection
Next Object
Note that the syntax in this traversal method is not applied as in the example. This is because a traversal method is a special case where Visual Basic allows you to start using the for next declaration.
Default method or Property
A method or property is the default property that a COM index gets from 0. Visual Basic allows programmers to automatically call default values when they do not know how to use method and property syntax. The related explanation looks at example 9.
Example 9
Set Object = Collection.item (2)
This is to get the second column in the collection and assign it to the object. Because the Item method is a default method. You can therefore use the Item method in Example 10.
Example 10
Set Object = Collection (2)
Object initialization
Create an object instance in ASP. You can use a statement like Example 11
Example 11
Set Object = Server.CreateObject ("Smum. Xcheck.1 ")
The parameter in the CreateObject method of the server side here is a ProgID (program ID). This ProgID is a uniquely assigned COM object. You must know the ProgID of this COM object to create this COM object.
Here's another way to create a COM object. You can use other COM objects to create a return object. Here is a collection of work. You're in a collection method returns the index number of the collection object that contains the COM object. The other object will return a COM object at any time. In example 12 you must declare with a similar set.
Example 12
Set Object = Collection.item (2)
The server side is a COM object. The example 11 and example 16 are very similar in many places. They are accessing another COM object from a COM object. The difference is that one uses the CreateObject method on the server side to create a server object that returns a COM object. The other is to return a COM object by using the Item method within a collection. So if you need to create another COM object in a COM object. Where does the service end object come from? The answer is whether it's a chicken or an egg. They're famous. A built-in COM object in ASP.
Built-in COM objects
There are six built-in COM objects in the ASP environment.
Server
Request
Response
Application
Session
ObjectContext
About ASP built-in objects here are not much to say.