1. Tech

Your suggestion is on its way!

An email with a link to:


was emailed to:

Thanks for sharing About.com with others!

Delphi and Active Forms
Let's create an ActiveX form that can be displayed and run from within Web browsers.
 Win prizes by sharing code!
Do you have some Delphi code you want to share? Are you interested in winning a prize for your work?
Delphi Programming Quickies Contest
 Join the Discussion
"Post your views and comments to this chapter of the free Delphi Programming Course"
 Related Resources
• Internet programming
• Web Development Tools

Active Form?
In Delphi, an ActiveForm is an ActiveX control that encapsulates a Delphi form.
An ActiveForm form is just a regular Delphi form. The form may contain any VCL or ActiveX components, including custom built VCL controls. We can add code, and respond to events just like we do for a form that belongs to a *standard* Windws application. The one difference is that the title bar on an ActiveForm does not appear on the control itself. It's just there at design time.
Creating an ActiveX form
Delphi provides an ActiveForm wizard to facilitate the creation of ActiveForms. The wizard creates an ActiveX library project to contain the ActiveForm and an active form, which you can customize.

To create a new ActiveX control (in this case ActiveForm), click on File|New, and choose the ActiveX tab. Then, double-click on the ActiveForm icon.
For this example, accept the default names for the ActiveForm name and implementation unit - just click OK. The wizard creates an ActiveX Library project, a type library, a form, an implementation unit and a unit that contains all of the corresponding type library declarations.

A few code lines...
Once the ActiveForm is created, you can add controls from the component palette. For this example try adding a TEdit component and a TButton.


Now, add the following code to the OnClick event of the TButton:

procedure TActiveFormX.Button1Click
(Sender: TObject);

   Web deploy
In order to use an ActiveForm on a Web page, you must use the Web Deploy option. To deploy the ActiveForm project, Web deployment options must be set appropriately, and the project must be compiled. Select Project|Web Deployment Options to open the Web Deployment Options dialog box. Deploying a simple ActiveForm is quite simple, and only requires that we enter data on the Project page of the Web Deployment dialog.

Some of the Web deploy options

If you choose to place the HTML (HTML Dir) file and the OCX (Target Dir) in the same directory, then Target URL entry should simply be './' to indicate the current directory.

Now, simply select Project|Web Deploy, the form will be deployed to the selected directory as a simple OCX, along with an test HTML page with a reference to the ActiveForm.

   It's working
Finally, we can see our ActiveForm working. If you open your browser (i.e. Internet Explorer) and point it to the address of the new HTML page, you should see your ActiveForm displayed.

Preview: Active form in Web browser

Try changing the text in TEdit, click on the Button; this will display a message box with your text.

Related resources
Here are some more tutorials, article, and sites related to creating and working with Active Forms from Delphi:
  • Designing and Deploying ActiveForms in Delphi - ActiveForms are a powerful and capable technology that can enhance your Internet and Intranet development capabilities. They can provide client applications to users across any network. They can even use database controls to run a data-based application across the network.
  • DAX FAQs - Explanations and Code Examples about the Delphi ActiveX Class Framework
  • Building ActiveX Controls with Delphi - This course is about how to build an ActiveX control using Delphi 3. In addition to presenting a tutorial on how to use Delphi 3's wizards to convert an existing VCL control into an ActiveX control, the course introduces areas where the control designer may want to extend the basic code, and provides in-depth explanation of Delphi's DAX class hierarchy.
  • ActiveForms not displaying in Internet Explorer - Why?
  • Converting a standard Delphi Form to an ActiveForm!
  • What directory is the ActiveForm in?
  • An article about Active X (focus on Delphi, MS VB and MS C++)
  • Linking Delphi and Javascript - how to create an ActiveX and link it to JavaScript in an HTML document.
  • Talking to ActiveForms - in this article, you learn ho to talk to ActiveForms from the most obvious host: Internet Explorer.

©2017 About.com. All rights reserved.