ActiveX Interface for ObjectStore

Chapter 1

Overview of the ActiveX Interface for ObjectStore

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:

ActiveX Automation is an object-oriented dynamically typed RPC mechanism that allows programmable automation controllers (typically programming languages or development tools) to access object servers by invoking properties and methods on the exposed interfaces.

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 following diagram shows the role the object server fills between an Automation controller and an ObjectStore database.



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.

Installing the ActiveX Interface for ObjectStore

The ActiveX Interface for ObjectStore is distributed as a self-extracting archive file that contains an automated SETUP program.

System Requirements

Minimum system requirements for the ActiveX Interface for ObjectStore are:

Windows 95 Patch Requirements

The original distribution of Windows 95 contained OLE libraries with a number of problems. You must install the following patches to Windows 95 in order to use this product successfully:

Note: DCOM is required whether or not you intend to use distributed configurations. It contains updated OLE libraries that are required for local use as well.

Installation

Install the ActiveX Interface for ObjectStore by setup. After setup performs the initial installation, it registers the supplied OSAX object servers in the system registry. It updates the system environment to refer to the new libraries and executables. It also adds the ObjectStore ActiveX AppWizard to the Microsoft Developer's Studio Tools menu.

Uninstalling the ActiveX Interface for ObjectStore

Select the Uninstall icon in the ActiveX Interface for ObjectStore's program group to remove the product. You can also use Add/Remove Programs from the Control Panel to remove the product.

Examples

The ActiveX Interface for ObjectStore includes example programs and databases. Each of the examples contains a Visual C++ 5.0 project with the source for the object server. You can build the project and register the object server for use. The examples will help you understand how to use the product and how to set up Visual C++ projects for it.

Books Example

The Books example is a simple database of book titles and authors. It includes a prebuilt database, an object server built using the ActiveX Interface for ObjectStore, and a Visual Basic executable that uses that object server to display the contents of the database.

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:

The source code for this example is common to both the ObjectStore and PSE products. It illustrates how an object server can target either storage system. The design workspace contains separate projects to build object servers for either product.

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.

The source code for this example is common to both ObjectStore and PSE products. It illustrates how an object server can target either storage system. The design workspace contains separate projects to build object servers for either product.

Build this object server in the OSAXTRAVEL - Win32 Release project configuration. The object server is intended for use with a database of catalog data. This database is supplied in prebuilt form in osaxtravel.db.

The Travel Web page obtains its database from the parent directory in which the control is located.

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 c:\odi\osax\examples\books\ directory contains the files for the Books example. See ReadMe.txt for an explanation of each file.

The following sections describe the different elements of the Books example.

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.

The object server is built from C++ code and libraries generated by OSAX based on information provided in the type description file, books.ost.

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.

To start the AppWizard, start Microsoft Developer Studio, and then select Tools->ObjectStore ActiveX AppWizard. The AppWizard screens are described in the AppWizard's on-line help.

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:

Global properties
The OSAX.Books object server provides two global properties to the Visual Basic project:

A subroutine from the Visual Basic application
The following subroutine from the Visual Basic application uses both of the global properties, ObjectStore and CBookElt:

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 Sub
The first statement in the subroutine:

ObjectStore.BeginTrans
uses ObjectStore to start a transaction in the database. The last statement:

ObjectStore.CommitTrans
uses 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 Books Database

The Books database contains three types of objects, each of which is defined in books.ost as a C++ class: Author, Book, and BookElt. The following table lists both the C++ class definitions for each of these classes and the corresponding Visual Basic properties and syntax used to access them:
Visual Basic CodeCode in books.ostC++ Class Definition
Dim Author As IAuthor
Dim AuthorName as String
Set Author = osDB("SampleAuthor").Value
AuthorName = Author.Name
class Author
{
 [propget]
 char* Name()data name;
 ...
};
class Author
{
public:
    char *name;
};
Dim Book As IBook
Dim BookName as String
Dim BookAuthor As IAuthor
Set Book = osDB("SampleBook").Value
BookName = Book.Name
Set BookAuthor = Book.Author
class Book
{
 [propget]
 char* Name()data name;
 [propget]
 Author* Author()data author;
  ...
};
class Book
{
public:
    char* name;
    Author* author;
};
Dim Books As IBookElt
Dim Book As IBook
Set Books = osDB("SampleBooks").Value
Do
    Set Book = Books.Book
    Set Books = Books.Next
Loop While Not Books Is Nothing
class BookElt
{
 [propget]
 Book* Book()data book;
 [propget]
 BookElt* Next()data next;
 ...
};
class BookElt
{
public:
  Book book;
   BookElt* next = NULL;
};

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.

Note: Constants for the loop differ in C++ and Visual Basic. The C++ NULL pointer value is as translated Null in OLE and as Nothing in Visual Basic.



[previous] [next]

Copyright © 1998 Object Design, Inc. All rights reserved.

Updated: 03/18/98 13:53:18