Creating an Active Server Object
Go Up to Creating an Active Server Page Index
An Active Server Object is an Automation object that has access to information about the entire ASP application and the HTTP messages it uses to communicate with browsers. It descends from AspTlb.TASPObject or AspTlb.TASPMTSObject (which is in turn a descendant of System.Win.ComObj.TAutoObject), and supports Automation protocols, exposing itself for other applications (or the script in the Active Server page) to use. You create an Active Server Object using the Active Server Object wizard.
Your Active Server Object project can be either an executable (exe) or library (dll), depending on your needs. However, you should be aware of the drawbacks of using an out-of-process server.
To display the Active Server Object wizard:
- Choose File > New > Other.
- Under Delphi Projects, select the ActiveX folder.
- Double-click the ActiveX Library icon. This creates a DLL project that will host the Active Server Object.
- Choose File > New > Other again.
- In the Delphi Projects folder, double-click the Active Server Object icon.
- In the wizard, give your new Active Server Object a name, and specify the instancing and threading models you want to support.
These details influence the way your object can be called. You must write the implementation so that it adheres to the model (for example, avoiding thread conflicts).The thing that makes an Active Server Object unique is its ability to access information about the ASP application and the HTTP messages that pass between the Active Server page and client Web browsers. This information is accessed using the ASP intrinsics. In the wizard, you can specify how your object accesses these by setting the Active Server Type:
- If you are working with IIS 3 or IIS 4, you use Page Level Event Methods. Under this model, your object implements the methods, OnStartPage and OnEndPage, which are called when the Active Server page loads and unloads. When your object is loaded, it automatically obtains an IScriptingContext interface, which it uses to access the ASP intrinsics. These interfaces are, in turn, surfaced as properties inherited from the base class (TASPObject).
- If you are working with IIS5 or later, you use the Object Context type. Under this model, your object fetches an IObjectContext interface, which it uses to access the ASP intrinsics. Again, these interfaces are surfaced as properties in the inherited base class (TASPMTSObject). One advantage of this latter approach is that your object has access to all of the other services available through IObjectContext. To access the IObjectContext interface, simply call GetObjectContext (defined in the mtx unit) as follows: ObjectContext := GetObjectContext;
You can tell the wizard to generate a simple ASP page to host your new Active Server Object. The generated page provides a minimal script (written in VBScript) that creates your Active Server Object based on its ProgID, and indicates where you can call its methods. This script calls Server.CreateObject to launch your Active Server Object.
Note: Although the generated test script uses VBScript, Active Server Pages also can be written using Jscript.
When you exit the wizard, a new unit is added to the current project that contains the definition for the Active Server Object. In addition, the wizard adds a type library project and opens the Type Library editor. Now you can expose the properties and methods of the interface through the type library as described in Defining a COM object's Interface As you write the implementation of your object's properties and methods, you can take a advantage of the ASP intrinsics to obtain information about the ASP application and the HTTP messages it uses to communicate with browsers.
The Active Server Object, like any other Automation object, implements a dual interface, which supports both early (compile-time) binding through the VTable and late (runtime) binding through the IDispatch interface.