contents   index   previous   next



Creating the CError ActiveX component

 

We’ll start with this component because it is the easiest one. Add a new form to your f90VBGUI project and name it FormError. Change the BorderStyle property of the form to Fixed Dialog, and add a label control (named Label1) and a command button control (named Command1) to the form (Figure 5). Change the caption of the command button to Ok, as shown in Figure 5.

 

Add the lines shown in Sample Code 1 to FormError. These lines will unload the form when the button control is clicked.

 

Now, we need to write a wrapper class for this form. Open the class CError and copy and paste the code in Sample Code 2. This creates a class that has one property (ErrorMessage) and one method (Show). The method loads FormError and sets the contents of Label1 to the value of property ErrorMessage. It then proceeds to show the form as a modal or modeless window, depending on the value passed in argument ShowModal.

 

Save your project and compile the ActiveX DLL (select File/Make f90VBGUI.dll in the Visual Basic Development Environment).

 

Let’s see how this new ActiveX object we have created looks to the outside world. Open the TLView utility that comes with f90VB, click File/Open (Figure 6). Because you have not yet registered this ActiveX object, you want to open the DLL file directly from the directory where the object resides. Click the button labeled Open from File on the lower right corner of the dialog box, navigate to the directory where f90VBGUI.DLL is stored (usually the same directory where you saved your project) and select the file (Figure 7).

 

Once TLView has opened the DLL, you will see that it has only one CoClass (CError) and one interface (_CError). Note that the CoClass implements interface _CError, which means that this ActiveX objects supports all the methods and properties exposed in this interface. As seen in Figure 8, interface _CError has three member functions: ErrorMessage (for property Put), ErrorMessage (for property Get) and Show (a method).

 

Note that the _CError interface inherits from IDispatch, which means it can be accessed through the f90VB Automation Library.

 

Now let’s write a simple Fortran subroutine that will use this ActiveX object to show an error message. We’ll put this subroutine into a Fortran module that we’ll use to group all the utility procedures in the application (Sample Code 3).

 

Subroutine DisplayError receives a single argument, ErrorMessage, which will be used later to set the property ErrorMessage of the CError object. The subroutine then creates an instance of the object using f90VB function CreateOleObject, sets the CError’s only property, and calls method Show which as we have already seen will display the error window.

 

If you cannot wait to finish the whole project to see your new ActiveX object in action, Sample Code 4 shows a simple main program (TestDisplayError) that calls subroutine DisplayError:

 

Use your Fortran compiler to compile this program (and the f90VBGUIUtils module), and link it against f90VB’s libraries. The links below show instructions on how to do this for several compilers.

 

Instructions to compile TestDisplayError with Absoft Pro Fortran

 

Instructions to compile TestDisplayError with Compaq Visual Fortran

 

Instructions to compile TestDisplayError with Lahey Fortran 95

 

Figure 9 shows a screen shot of what you would see when you run this test program.

 

Ok, so now we have a nice simple ActiveX object to display any error messages generated by our application. Let’s see what needs to be done for the other objects.


Creating the CAbout ActiveX component