How To: Creating an Active Form

Posted: (EET/GMT+2)

 

How To: Creating an Active Form

Level: Beginner


Delphi 3 contains a very impressive new feature named Delphi ActiveX Framework, or DAX for short. DAX allows you to do many things, for example ActiveX forms to run in a WWW browser's window. In this How To you will learn how to create a very simple ActiveX form object, which you can run and manipulate through Microsoft's Internet Explorer (IE).


Starting an ActiveX Library Project

In Delphi, creating an OCX library which contains an ActiveForm is no different from creating any other project. First, choose File|New..., click the ActiveX tab, and select the ActiveX Library project. You need to give some (descriptive) filenames here.

Delphi opens an empty project for you. The project is a library, so you cannot simply run it within the IDE -- but more of this later. Next, you need to create a form. This form is the one you will see when you open the project through your web browser.

To create an ActiveForm, choose File|New... and select the ActiveX property sheet again. Click ActiveForm, and the OK. You now see an ordinary looking form, just like it were a normal form.

On the surface the form looks and behaves as normal, but underneath the surface happens a lot. For example, the form's unit contains many predefined methods. Also, if you open the TLB (for TypeLiBrary) file, you will see that Delphi does really many things for you.


Creating the main ActiveForm

The next step in creating a ActiveForm is actually making the form do something useful. The code sample you can download below is a BPM (beats per minute) counter. With it you can quite easily calculate the BPM's of your favorite dance track even if you don't have professional DJ equipment.

Anyway, creating the form is no different from creating a normal form, just like I said before. Simply drop some control onto the form from the component palette, and write some event handlers.

For this how to the finished form should look the one below. Note that the caption is quite dummy, but it doesn't matter as it doesn't appear when viewed through the browser.


    The finished ActiveForm.




Deploying an ActiveX library

Now you ActiveX library is finished, and you are ready to deploy it. In Delphi this requires two steps.

Firstly, you need to specify some options, so that Delphi knows for to deploy your project. Choose Web Deployiment Options from the Project menu. The most important settings in the dialog box are the directory settings.

For the Target directory, you need to specify a physical path name. This is the directory Delphi puts the resulting OCX file in. The OCX file contains your entire ActiveX project.

The Target URL is the URL directory where the browser can find the OCX. For example, if you are using IIS (Internet Information Server), you specify the target as the real directory of the OCX, and the URL is then the virtual directory for the OCX configured using the Internet Service Manager utility.

The HTML directory is usually exactly the same as the Target dir.

After you have chose the directories (and possibly other settings), choose Web Deploy from the Project menu. If everything goes well, you will see a flash of a Windows copy dialog.


Looking your ActiveForm through the browser

After deploying the library, you are ready to fire up your browser. Open for example IE, and type the Target URL plus the name of your project appended with the ".htm" extension. If you typed the URL correctly, you will see the following warning (in IE):


    A warning dialog shown by IE.



This dialog box appears because you haven't signed your ActiveX component. Because you know your ActiveX form doesn't contain any misbehaving code, just click Yes. You will see the following:


    The finished ActiveX library running within IE.



Once open and running, you can play with your ActiveX form just like it were an ordinary form! Isn't Delphi amazing?


Conclusion

In this How To you have learned how to create a very simple ActiveForm using Delphi. Of course, ActiveX is a complex technology, and we won't have the space to cover it here. However, just start examinig the code created by Delphi, and you will see that it is very interesting. Also, don't forget to read the Developer's Guide!