Chapter 7. Using Components

One of the most powerful features of ASP is its tight integration with COM. Due to this relationship, Active Server Pages can easily use COM objects, thereby extending the feature set of ASP. Microsoft provides several ready-to-use COM objects with IIS, which will be the focus of this chapter; however, there is an entire market of third-party COM objects created by companies independent from Microsoft, which will be discussed in length in the next chapter. Furthermore, you, the developer, can create your own custom COM objects for use in your ASP projects, which we’ll touch upon briefly in this chapter.

Being able to use COM objects in ASP pages—be it Microsoft-created, third-party-created, or custom-built—is what gives Active Server Pages their great flexibility. Without the ability to use COM objects, ASP would be painfully limited in its scope. After all, ASP only provides a handful of intrinsic objects for the developer to use. These built-in ASP objects don’t grant the developer much more than the ability to read from the HTTP request stream, write to the HTTP response stream, and gather information about the web server. To extend ASP, components must be used.

To fully understand the importance of being able to use COM components in an ASP page, imagine for a moment that suddenly, ASP’s ability to use COM objects is taken away. Since ADO is nothing more than a collection of Microsoft-provided COM components that aid in database interactions, if an ASP page could not instantiate and utilize a COM component, developers would not be able to create data-driven web sites using Active Server Pages.

Using a high-level programming language like Java, Visual C++, or Visual Basic, developers can create custom COM components for use in ASP pages. Using custom COM components is a virtual necessity for large web sites with complex business rules. In this chapter we’ll examine what benefits custom COM components bring to the table and when they should be used. We’ll also discuss Windows Script Components, which are scriptable COM objects, and compare them to classical, binary COM components.

In this chapter we’ll also look at some of the lesser-known Microsoft COM components. Almost every developer is familiar with ADO, but not as many have had working experience with Ad Rotator, Browser Capabilities, and Content Linker.

COM—A Quick Overview

This book has focused on code reuse and design for ASP applications. Throughout the past seven chapters, we’ve created various scripts and classes that could easily be reused in other ASP scripts and web projects with minimal effort. While following rigorous ASP application design techniques makes future ASP projects a breeze, it does not lend itself well to future projects using other development tools.

For example, if you wanted to create a banner rotation system on your web site, you could write a class that would randomly pick one advertising banner from a set of potential banners based upon some developer-defined weighting of the various banners. Creating such a system wouldn’t be too difficult, and could be done in a highly reusable way using classes. Now, imagine that you were interested in creating a random image-viewing program using Visual C++. You ought to be able to reuse the random banner rotation script to display a random image, since both programs are incredibly alike. However, since the banner rotation system was written as a VBScript class, you cannot directly use it in your Visual C++ random image viewing program.

Tip

A COM component to assist in banner rotation already exists. This component, named Ad Rotator, is discussed in detail in this chapter.

It has long been the dream of developers to be able to write and compile a program just once, and have it able to be used by any program on any platform on any computer with maximum ease. COM, which stands for Component Object Model, is a Microsoft-backed standard for creating “use anywhere, anytime, anyhow” components. With COM, a developer only needs to write the code and compile the object once. With this compiled object in hand, any programming language or tool that can utilize COM can then create an instance of the COM object.

Tip

This chapter does not contain a thorough explanation of COM. If you are interested in learning the nitty-gritty details of COM, I highly suggest you read Inside COM, by Dale Rogerson, published by Microsoft Press.

COM components can be created in a wide array of programming languages, including Java, Visual C++, and Visual Basic. A fully functional COM component can be instantiated and used from a wide array of programming tools and languages. If you are proficient in any of these languages, you can create custom COM objects for use in your ASP pages. Later in this chapter, we’ll discuss the benefits of custom COM objects and when they should be used. This chapter does not, however, delve into a detailed discussion on how to build custom COM components. For a great resource on building custom COM components for use in ASP pages, be sure to read Shelly Powers’s Developing ASP Components (O’Reilly & Associates).

In summary, COM components allow for the development of components in a plethora of languages that can be compiled once and used virtually anywhere.

Tip

COM components can also be developed using any ActiveX Scripting Engine, such as VBScript, JScript, PerlScript, or Python. We will discuss these COM components, referred to as Windows Script Components, in Section 7.4.3 later in this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.147.87