Top
PowerCOBOL V11.0 User's Guide
FUJITSU Software

Chapter 11 Creating and Using Custom Controls

This chapter discusses creating and using custom OLE and ActiveX controls in PowerCOBOL applications. Custom controls are one of the most exciting and powerful additions to Windows applications.

ActiveX is a specification detailing how components should communicate with each other. It is built on top of Microsoft's COM specification, which is an object oriented design and set of low level interfaces detailing how objects developed in separate languages should communicate with each other.

ActiveX is an extension of Microsoft's OLE (some people even claim that it is a replacement for, or a newer version of OLE). For the purposes of this chapter, we will treat the terms "ActiveX" and "OLE" as one and the same.

A PowerCOBOL developed custom control typically exists as a COM enabled .DLL file. It may itself contain other controls. PowerCOBOL makes it quite simple to take almost any PowerCOBOL application and turn it into a custom control.

Controls may have events, methods and properties associated with them that are exposed to outside applications to manipulate.

Controls are in essence the basic building blocks from which many Windows applications are created. The most common uses of controls are the various graphical development elements such as command buttons, check boxes and text boxes.

Each time you place a command button on a form, you are using a control. You need not worry about creating the actual low-level code to create the graphical element and manage its low level behavior. Instead, this behavior is managed automatically.

There are many instances in application development where developers desire to construct an application using pluggable, already tested software components. This is typically what you are doing as you design a PowerCOBOL form within the form editor, by dropping controls (application components) onto a form.

Custom controls may consist of simple graphical design elements such as a command button, or more complex controls such as timers, animation controls, or a print control.

Custom controls are not required to be simple graphical development objects as well. A custom control may be an entire highly complex application that you may wish to reuse within other applications. It may also be invisible at runtime to the end user.

An example of a more sophisticated control is Microsoft's Rich Text Box control. This control is an extension of the standard text box control. Using it, you may display text using multiple colors, fonts and sizes in the same rich text box. The rich text box control also does away with the 64K size limitation of a standard text box.

A control may also be an application within itself. For example, let's suppose you wanted to create a set of SQL routines to manage data access to a database. You could create a PowerCOBOL application that performs all of the database I/O, error checking and logging.

You could then build this application as a control and register it to Windows to make it available to other applications as a control. Other Windows applications could then insert this control into themselves and utilize it.

One of the beauties of creating and using custom controls is that these controls may typically be shared between different development languages and environments within Windows. For example, you can use PowerCOBOL to create a custom ActiveX control to insert into a web page being developed using Microsoft's FrontPage.

You could just as easily insert a PowerCOBOL developed custom control into a Visual Basic application.

Note that in order to deploy a custom control which has been created using PowerCOBOL, the PowerCOBOL runtime system must be available on the client machine. Your installation process on the client machine must also register the control with Windows on the client machine to make it available for use on that machine. Windows comes with a standard utility named REGSVR32.EXE that you can call and provide the name of a COM enabled .DLL file to register to the system as a control.

In this chapter, you will taken through the process of creating a simple, yet useful custom control that you can use in any of your applications.

This control will initially be a simple clock control with a display showing a digital clock that actually ticks seconds in real time.

You will then enhance this control to include the current date then enhance it further using custom methods to provide additional functionality and interaction with an application that wishes to make use of this control.

You are free to use this control in any of your future applications if you find it useful.