VB 4.0 in the Flesh
Keith Pleas examines the new release of Visual Basic and some of its exciting new features involving OLE.
September 30, 1995
VB 4.0 in the Flesh
Microsoft has just released a major update to its very successful application development tool, Visual Basic. Following closely on the heels of Windows 95, Visual Basic 4.0 (VB4) enables you to rapidly develop full-featured 32-bit applications that run on both Windows 95 and Windows NT platforms.
VB4 comes in three flavors: the Standard and Professional Editions, as VB3 did, and the new Enterprise Edition. The Standard Edition includes basic functionality but doesn't include the more advanced features highlighted for the other two. It is targeted primarily at hobbyists and beginners. The Professional Edition has support for 16-bit executables, creates Object Linking and Embedding (OLE) Automation servers, and includes a library of useful third-party controls.
The Enterprise Edition adds the capability to do OLE Automation over a network, support for a new Open Database Connectivity (ODBC)-based database technology called Remote Data Objects (RDO), and a variety of advanced client/ server-component testing and management tools. It also bundles in a code profiler and Microsoft Sourcesafe for project and version control. Although individual developers will probably be comfortable with the features of the Professional Edition, teams of developers building distributed client/server applications will all but require the advanced capabilities of the Enterprise Edition.
In addition to support for Win32 features on both Professional and Enterprise platforms, VB4 includes a number of powerful enhancements to previous versions. While the overall look and feel of the tool hasn't changed much, there are a number of changes "under the hood," and the full list of new features is staggering. Many of them involve VB4's new OLE capabilities:
Complete container support for OLE controls
Full client support for OLE documents (drag and drop, menubar, and toolbar)
Ability to create OLE Automation servers--Professional and Enterprise Editions
Ability to create in-process OLE dynamic link libraries (DLLs)--Professional and Enterprise Editions
Remote automation--Enterprise Edition
VB's strong database support also has been enhanced:
32-bit Data Access objects
Substantially improved data control
Data-bound grid, list box, combo box, OLE data-source controls
ODBC-based remote data control--Enterprise Edition
Data Explorer Setup Wizard--Enterprise Edition
Improved Crystal Reports--Professional and Enterprise Editions
The list of improvements is broad; other highlights include:
Class modules
Conditional compilation (using built-in 16-bit/32-bit operating-system tokens as well as user-defined tokens for such things as debug code)
Collection classes
VB Integrated Development Environment (IDE) extensions
Completely new Setup Wizard (necessary to handle the substantial application setup requirements including determining binary-level dependencies, OLE requirements, all registration, and network installation scripts)
Numerous language features (including true OLE variants, which can now contain arrays and object pointers)
Improved Printer object
Automatic versioning
Resource file support which allows attaching strings, graphics, and binary "chunks" for such things as AVI files without recompiling
New Error object and much improved error handling
Rather than give you a list of all the new features, I'll focus on the functional areas that I feel are most important.
Win32 Applications
Microsoft is positioning VB4 as the primary tool for developing Windows 95-certified logo-bearing applications, which, among other requirements, must run under Windows NT. NT users are already familiar with some of the requirements, such as long filenames and Universal Naming Convention (UNC) pathnames, while others use features such as large and small icons that are only available when running the new shell (available in beta form for NT from a variety of Microsoft-controlled sources).
In addition, while not a requirement per se, Microsoft strongly suggests that you take advantage of the new 32-bit controls distributed with both Windows 95 and Windows NT 3.51. These controls include the often requested Rich Text Format (RTF) control as well as a 32-bit common-control DLL that contains the following controls:
TabStrip
Toolbar
StatusBar
ProgressBar
TreeView
ImageList
ListView
Slider (Trackbar)
Up-Down (equivalent to SpinButton)
Header window (in ListView's properties under Column headers)
All these controls are exposed through a Wrapper OLE control added to a project just like any other custom control. (Screen 1 shows many of these controls.)
VB4 also includes another OLE control, SysInfo, for handling Plug-n-Play (PnP) messages. Ideally, these messages would come in at the application level. Unfortunately, however, VB can only attach code to form- and control-event procedures. You have to use a custom control to intercept the PnP device messages (to handle screen-metric changes, you must trigger the Resize events of all loaded forms). VB4's Tools/Custom Controls dialog is shown in Screen 2.
VB4 and Objects
The VB4 IDE itself is an OLE Automation server: the forms, controls, classes, and modules of the loaded project are collections of objects that are controllable by OLE Automation. Using VB4, you can create add-in modules that integrate into the VB4 IDE and provide:
Source code control (e.g., Microsoft's own Sourcesafe)
Task Automation Wizards
Object libraries
Form, code, style generators (templates)
CASE, data modeling, and design tools
Expert systems to optimize VB projects
Although VB4 adds some object-oriented features, it's still more in the "object-using" tool category than some of its competitors--most notably Delphi. In particular, VB4 adds strong support for encapsulation via its new Class modules, and it's possible to create polymorphic methods, but there's no form of object inheritance. Instead of allowing you to derive objects from other objects, VB4 focuses on enabling you to reuse existing--and, in many cases, commercially available--object libraries. And since you can integrate Object Creation Wizards into the VB4 environment, you can also build tools.
In addition to the familiar code modules, VB4 adds powerful new class modules. Each class module defines a single object class; you can have many classes in a project. It's customary to organize these classes into an object model to help in understanding their relationships. Each class has a variety of properties (implemented as public variables) and methods (implemented as public subroutines). You can also define property GET/LET subroutines to control access to the properties (e.g., to handle data validation when a program using an object attempts to set one of its properties). You can organize objects into collections (e.g., a collection of worksheets in a workbook or a collection of students in a class). They are useful in managing a group of related objects.
The addition of custom classes in VB4 parallels the introduction of the new built-in Collection type for managing them. The Collection type provides automatic support for adding, deleting, and iterating an object collection. However, the fact that these things are handled automatically can lead to a loss of encapsulation where it's important to tightly manage which object methods and properties are public and which are private. Thus, you may well want to skip the built-in class and implement your own custom class, called Collection.
OLE Automation
While the Class objects are important in writing almost any non-trivial VB application, they really shine when compiled into an OLE Automation server and called from an OLE Automation controller, such as VB, Excel, or Access. It's easy to extend, for example, Excel with pop-up dialogs that are actually VB4 forms. You can also build large, complex business applications by piecing together various programmable components. From the controlling application, the most common way to add an object library is via the Tools/References dialog (see Screen 3).
When you add an object library, information about all its objects, methods, and properties becomes available to the controller's design environment via a type library, which you can typically examine with an object browser (see Screen 4). Using a type library allows the controller to early-bind to objects (i.e., verify that they exist and obtain an efficient pointer to them), enables syntax checking in code (which helps reduce run-time errors), and provides a convenient way to access whatever Help documentation might exist for the objects in the object library.
Creating an OLE Automation server is simple and requires (roughly) the following four steps:
Create a class
Implement methods and properties
Set the class's Public property to True
Set the project's Startmode to OLE Server
This simple process shields you from a lot of behind-the-scenes activity. VB4 automatically resolves any binary dependencies, creates the executable object library, generates the type library, adds and modifies entries to the system's registration database, creates and maintains version information for all the objects, and generates executable-file version information. The net results are easy to create, reusable components that can Wrap existing functionality, generate reusable programmable objects, and encapsulate business rules--and give them all a developer-friendly interface.
The Enterprise Edition of VB4 also provides a mechanism for doing OLE Automation across a network. Remote automation is transparent to both the user and the object developer. The same .EXE runs locally or remotely, and a small utility application on each end of a remote connection handles the communications. The network communication is based on the industry-standard Distributed Computing Environment (DCE)/Remote Procedure Call (RPC), is transport-independent (TCP/IP, SPX, NetBIOS, and datagrams are supported), and is upward-compatible with the true Distributed OLE that Microsoft plans to ship with Cairo. Managing the large number of objects that businesses will create would be a huge task, so the Enterprise Edition also includes a Component Manager (see Screen 5).
3-Tiered C/S Data Access
VB4 expands on the strong database capabilities of VB in a number of ways. First, the included Jet engine has been upgraded to match the 3.0 version now shipping with Access 7.0. Not only is Jet now a 32-bit engine, but you now can access all its objects programmatically instead of being restricted to those available in Jet 1.0--the Jet 2.0 compatibility layer exposed no new objects. You can now program in referential integrity, security, parallel transaction processing, replication, and cascading updates and deletes.
VB4's Enterprise Edition ships with RDO, a completely new database technology. It's a highly optimized layer on top of an ODBC interface. Similar to the familiar--and vastly improved--Jet-based data control already in VB, RDO interfaces with a Data Source control to link individual controls to database fields. The Enterprise Edition ships with Data Source controls for SQL 4.2, SQL 6.0, and Oracle 7.x. Microsoft has also documented an open Data Source control interface and expects third-party database vendors to create and distribute custom versions tailored to their database products. The Enterprise Edition also includes a number of tools for managing RDO databases, including a Data Explorer Setup Wizard that creates the tables, logins, and data sources needed to run the client application.
Tremendous Capabilities
While there may be a few things you can't do in VB4 (create OLE controls, OLE insertable objects, or conventional DLLs), the tool's capabilities are tremendous, particularly for creating Win32-based applications to run under Windows 95 and Windows NT. However, because of the OLE system DLLs, all VB4 applications destined for NT 3.51 and above require the latest DLLs. Although the updated 16-bit OLE DLLs can be distributed with a 16-bit VB4 application, they won't actually install on NT because they would overwrite the OLE DLLs distributed with NT and destroy--among other things--the 16-bit to 32-bit OLE thunking (translating the call parameters) provided by the 32-bit operating systems.
Visual Basic 4.0 |
Contact: Microsoft * 206-882-8080 |
Prices: Enterprise Edition $999, Professional Edition $499, Standard Edition $99, (Upgrades cost less.) |
About the Author
You May Also Like