The ActiveX Interface for ObjectStore (OSAX) exposes ObjectStore databases and their contents to Visual Basic and other ActiveX Automation controllers and scripting hosts. Database objects are implemented in ObjectStore using C++ and described in the ObjectStore schema using a superset of the C++ object model. The ActiveX Interface for ObjectStore provides a mapping between the ObjectStore schema and the object model underlying OLE. It also provides a mechanism for communicating object references and values between an ObjectStore database and an Automation controller.
OSAX features
The ActiveX Interface for ObjectStore includes the following features:
For detailed information about the OSAX ActiveX interfaces, see Chapter 6, ActiveX Interface Reference.
OSAX and the ActiveX architecture
There are three key ingredients in the ActiveX architecture that allow it to represent the contents of ObjectStore databases with good performance and fidelity:
The ActiveX Interface supports several different configurations for the OSAX object server and several means of making type information available to OLE. The ActiveX Interface enables you to expose objects in an ObjectStore database, making them accessible to an ActiveX client (such as Visual Basic Script) with little or no direct programming of COM interfaces.
Build this object server in the Books - Win32 release project configuration. This object server can then be used directly by the Visual Basic 5 application in the vbclient subdirectory. The Visual Basic 5 application contains an option to create a new database.
The Books example is a good starting point to learn how to build and use an OSAX object server; see A Tour of the Books Example.
Portfolio Example
The Portfolio example illustrates a simple ActiveX Interface for ObjectStore application implemented in C++ and Visual Basic using an OSAX object server. The application provides a user interface to do the following:
Build this object server in the OSAXPORT - Win32 Release project configuration. The object server is intended for use with a database of stock data. This database is supplied in prebuilt form in osaxport.db.
The Visual Basic 5 version of the Portfolio application provides an Open Database dialog. You can use this dialog to locate the prebuilt Portfolio database (osaxport.db) and open it with your newly built control.
For more information about the Portfolio example, see Chapter 5, The Portfolio Sample Application. This example is particularly pertinent to applications that work with collections.
Travel Example
The Travel sample application demonstrates the use of the ActiveX Interface for ObjectStore with Internet Explorer. It uses the Visual Basic Script engine to orchestrate the client-side presentation of multimedia content (various vacation experiences) stored in the database. For more information about the Travel sample application, see the Travel ReadMe.txt file. A Tour of the Books Example
This section introduces you to the elements of an OSAX project and to the process of creating a project, using the Books example that comes with OSAX. The Books example uses ActiveX with Visual Basic to access objects in a prebuilt ObjectStore database of book titles and authors. After building the OSAX object server for this example, you can access the database from Visual Basic and display the following form:
The Visual C++ Project
The OSAX object server for the Books example is built using a Visual C++ project. This project contains all the C++ source code for the project, as well as the type description file and database schema definition. The Books example project files are in the directory c:\odi\osax\examples\books\objectserver directory. You can examine, modify, and build that project using Microsoft Visual C++ 5.0. The Object Server
The OSAX.Books object server is an ActiveX object that provides access to the contents of Books, an ObjectStore database of book titles and author names. The object server consists of a dynamic link library (DLL) that links application-specific methods with the database libraries and implements the interfaces required for ActiveX Automation, scripting, and other capabilities. The object server DLL is associated with an ActiveX type library that defines the classes, interfaces, properties, and methods provided by the object server. Type description file
The type description file (books.ost) is a source file that implements the OSAX object server. It includes descriptions of the ActiveX interfaces that are to be built into the object server and used for accessing objects in the database. For detailed information about type description files, see Chapter 2, Building OSAX Object Servers.
Note: OSAX also supports the Microsoft Active Template Library (ATL) as a way to create COM interfaces for persistent objects stored in an ObjectStore database. Using ATL instead of type description files requires experience with ATL and C++, but it provides more flexibility and control when customizing COM interfaces.
The ObjectStore ActiveX AppWizard
The type description file books.ost was initially generated by the ObjectStore ActiveX AppWizard that is added to the Microsoft Developer Studio Tools menu when you install OSAX. The AppWizard can be used to create an OSAX object server. Since OSAX requires custom build rules, you can use the AppWizard to generate template files and create a Microsoft Developer Studio project. After generating these files, you can modify them for your specific project, as was done with the type description file for the Books example. The Visual Basic Project
The file books.vbp contains the Visual Basic 5.0 project that enables you to build a Visual Basic application to access the database. The Visual Basic project for the Books example does (among other things) the following:
Sub DisplayBookList() ObjectStore.BeginTrans Dim BookElt As IBookElt Dim Book as IBook Dim Author, Title As String Set BookElt = osDatabase.Value("Books", CBookElt) Do Set Book = BookElt.Book Author = Book.Author.Name Title = Book.Name List1.AddItem Author & " - " & Title Set BookElt = BookElt.Next Loop While Not BookElt Is Nothing ObjectStore.CommitTrans End SubThe first statement in the subroutine:
ObjectStore.BeginTransuses ObjectStore to start a transaction in the database. The last statement:
ObjectStore.CommitTransuses it to commit the transaction, freeing resources and allowing other processes to modify objects that were read from the database.
The following Set statement
Set BookElt = osDatabase.Value("Books", CBookElt)passes CBookElt as an argument that specifies the class of BookElt, which is the named object or root object to be retrieved from the database. The CBookElt argument is used for type-checking purposes. Once the root object has been retrieved and type-checked, all further access to ObjectStore objects is automatically type-checked according to the declared Visual Basic types.
The expression osDB("SampleAuthor").Value looks up the database root named SampleAuthor in the specified database and returns its value as an object that can be observed using its defined property names.
Updated: 03/18/98 13:53:18