home account info subscribe login search FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Advanced Visual Basic Techniques
(Publisher: John Wiley & Sons, Inc.)
Author(s): Rod Stephens
ISBN: 0471188816
Publication Date: 06/01/97

Search this book:
 
Previous Table of Contents Next


To prevent a control from being abused, it should check data values in its property procedures to see if they make sense. The control should ensure that values do not force it to access array entries that do not exist. It should place reasonable restrictions on the allowed values. The earlier example, where NumPoints was set to 1 billion, is dangerous because it allows the property to be set to a ridiculously large value. Setting an upper limit of 100 or 1000 points should provide enough space under most circumstances.

The following actions may also be dangerous when they take input from a control’s properties or when values are specified by parameters to a method:

•  Reading, writing, or deleting a file with a name supplied by a property or parameter
•  Using a disk drive with a name supplied by a property or parameter
•  Inserting, updating, or retrieving information in the Windows Registry using a value supplied by a property or parameter
•  Executing an API function using a value supplied by a property or parameter
•  Referencing array entries with indexes given by properties or parameters
•  Creating data values or other objects with the number given by a property

When creating a control’s Internet distribution package, as described in the following sections, the developer can specify whether the control should claim to be safe for initialization, safe for scripting, or both. These flags should be set only if the control has been thoroughly tested and if it really is safe. When a control is flagged as safe, the developer promises that no harm will come to the user from the control.

Certificate Authorities

Even with all these precautions, the eventual viewers of the control have little reason to believe a control is safe. After all, they do not know the developer personally.

One way to provide some sense of security is to use a certificate authority. A certificate authority is some trusted organization that keeps a record of the control. Using digital signature techniques, the authority marks the control with information that allows a browser to verify that the control has not been modified since it was originally published. When a browser downloads the control, it checks to see if the control has been modified. If it has been, it warns the user that the control may no longer be safe.

Even with a certificate authority, the control developer is still responsible for the behavior of the control. If the control is damaging, the user can consult the authority to learn who published it. The authority cannot prevent damage, but it can help hold the control designer responsible when damage occurs.

Displaying ActiveX Controls

Displaying an ActiveX control on a Web page is not too difficult using the HTML OBJECT statement. This statement creates the control and initializes its width, height, and other properties.

The OBJECT Statement

The OBJECT command takes several parameters. WIDTH and HEIGHT indicate the size the object should have on the Web page. CLASSID gives a class identification string for the control. This rather bizarre string is the class ID used by the Windows registry to identify the control. An easy way to determine a control’s class ID is described in the next section.

The CODEBASE parameter tells where the Web browser can find a copy of the control if it is not already located on the user’s computer. It also includes the control’s version number. If the control is not registered on the user’s machine or if the version number in the OBJECT statement disagrees with the registered control’s version number, the browser automatically loads the new version.

After the OBJECT statement specifies this basic information, PARAM statements can initialize the control’s properties. When the page has given values for all desired parameters, an </OBJECT> statement ends the object definition.

The following HTML code shows how a histogram control might be created on a Web page. The control’s cabinet file is named Histgram.CAB and is located in the /Histgram directory on the server www.mysite.com. The cabinet file tells browsers where the control’s .OCX file is located and what other controls might be needed to run the control. In this example, the control’s BarForeColor property is initialized to 16711680.

<OBJECT ID=“Histogram1” WIDTH=200 HEIGHT=184
CLASSID=“CLSID:75CDDDBA-9A2A-11D0-AA34-0000E8167669”
CODEBASE=“http://www.mysite.com/Histgram/Histgram.CAB#version=1,0,0,0”>
    <PARAM NAME=“BarForeColor” VALUE=“16711680”>
</OBJECT>

Learning Class IDs

The easiest way to learn a control’s class ID is to use the Setup Kit Wizard included with Visual Basic 5 to create an Internet distribution kit for the control. The Setup Wizard’s first screen asks for the project’s name and setup options. To prepare the control for downloading to Web clients, the Create Internet Download Setup option should be selected, as shown in Figure 17.5.

When the Wizard asks for the distribution location, the directory where the downloadable files will be placed should be specified. The directory must be one that is accessible to Web clients. Otherwise, users trying to view Web pages that contain the control will be unable to download it.

The Wizard asks for packaging instructions, as shown in Figure 17.6. The Safety button displays a dialog where the control can be flagged as safe for initialization or safe for scripting.

When the Wizard finishes, it creates several distribution support files, including the control’s .CAB file, in the directory specified earlier. One of the other support files is named after the control but with an .HTM extension. For example, when building an installation kit for the histogram control Histgram.OCX, the Wizard also creates Histgram.HTM. This file contains a short example Web page that includes the class ID for the control. This value can be copied into other Web pages that use the control.

An Example Page

The following HTML code is in the file Histgram.HTM in the compact disk’s Ch17 subdirectory. Before you can use this page, you will need to modify the code to fit your system. First, use the Setup Wizard to create an Internet distribution package for the Histgram.VBP project contained in the Ch16 subdirectory. Examine the resulting .HTM file to find the control’s class ID. Update the file Histgram.HTM so that it uses this class ID.

Next, change the file’s CODEBASE parameter so that it indicates the location of the Histgram.OCX file produced by the Wizard. This step is not really necessary as long as you run the Web page on the computer you used to create the distribution package. That computer already knows where to find a copy of the control. It is necessary, however, if another computer will load the control.

This Web page displays a histogram control. First it uses the OBJECT command to create and initialize the control. It uses the PARAM statement to make the control’s tic marks blue.


FIGURE 17.5  Selecting Setup Wizard options.

Next, the document uses VBScript code. Not all browsers understand VBScript and those that do not can fail in a couple of different ways. Netscape Navigator 2.02 realizes that it does not understand VBScript and quietly ignores everything it finds between the <SCRIPT LANGUAGE=“VBScript”> statement and the closing </SCRIPT>.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.