ActiveForms, Part I
ActiveForms, Part I
http://bcbjournal.org/articles/vol3/9910/ActiveForms__Part_I.htm
ActiveForms, Part I
by Bob Swart In this article, you will see how to build and deploy ActiveForms using C++Builder all without writing a single line of code! In Part II of this series I will show you how to deploy your ActiveForms. In Part III, I will show you how to build thin client ActiveForms by incorporating Inprise MIDAS techniques.
Creating an ActiveForm
TActiveForm is the base class for a VCL form exposed as an ActiveX control. TActiveForm represents a form that is created via the Active Template Library (ATL) and used as an ActiveX control in a host application. This makes it very easy to embed visual and non-visual components on the ActiveForm. The result is a complex ActiveX control that can be used in C++Builder itself, on a Web page, or in other development environments such as Visual Basic or Delphi.
To create an ActiveForm in C++Builder, first select File | New from the main menu. Next click the ActiveX tab in the Object Repository, and double-click the ActiveForm icon. When you do, the ActiveForm Wizard will be displayed. In the ActiveForm Wizard, you need to specify the name of the ActiveForm (the default name is ActiveFormX), the name of the implementation unit, and the project name. When you change the ActiveX name, C++Builder will change the name of the implementation file and the project file. You can change the filenames, of course, to use names you prefer. The project name will also result in the final name of the ActiveX control. For this example I named the project ActiveF so the final output file will be named ACTIVEF.OCX. Starting with version 4 of C++Builder, the threading model is set to Apartment. This model is required to use the ActiveForm in Internet Explorer version 4 or higher. You have the option to include an About box for your ActiveForm, a design-time license, and version information. Including a design-time license will result in an ActiveForm that can only be used in a run-time environment, or at design-time if the license file is present. More importantly, choosing this option will also result in an ActiveForm that wont work inside Internet Explorer because the ActiveX is designated as a design-time control. I seldom use this option, but it can certainly be useful for demo editions of commercial ActiveForms. The option that you should always check is Include Version Information. You'll need this information when deploying new versions of your ActiveForms (updates, bug fixes, and so on). Obviously, without version information, there is no way the browser can detect that an update is available for download.
An ActiveForm client
As an example, you will create an ActiveForm that shows a master-detail relationship between two tables. First, resize the form to 600 x 400. Next drop a TPanel component on the ActiveForm, clear its Caption property, and set its Align property to alTop. Now drop a TTable (name it TableCustomer), a TDataSource, and a TDBNavigator on the panel. Set the DataSource components DataSet property to TableCustomer, and the DBNavigators DataSource property to DataSource1. Set the Tables DatabaseName property to BCDEMOS, and its TableName property to CUSTOMER.DB.
1 of 3
15/06/2012 4:24 PM
ActiveForms, Part I
http://bcbjournal.org/articles/vol3/9910/ActiveForms__Part_I.htm
Now double-click on the table component to invoke the Fields Editor. Right-click in the Fields Editor and choose Add all fields from the context menu. This will add all fields from the table into the fields list. Select the fields you want to display on the ActiveForm, drag them to the client area of the ActiveForm, and arrange them to your liking. I added the customer number and address information so I ended up with the form shown in Figure A. Figure A
The ActiveForm looks like a regular form at design time. Before you continue, you can make sure the database navigator bar always stays at the upper-right corner of the ActiveForm. In C++Builder 4 you can do this easily by modifying the DBNavigators Anchors property. Set the Anchor propertys skLeft value to false, and akRight to true. Now the DBNavigator will always be in the upper-right corner of the ActiveForm.
Figure B
2 of 3
15/06/2012 4:24 PM
ActiveForms, Part I
http://bcbjournal.org/articles/vol3/9910/ActiveForms__Part_I.htm
package is built your ActiveForm will be on the ActiveX page of the component palette. Now create a new project. Select the ActiveFormX control from the ActiveX page and drop it on your form. Resize the control to your liking and run the program. Its as easy as that! Figure C shows the ActiveForm hosted in a C++Builder program. Figure C
Conclusion
ActiveForms are convenient for creating complex ActiveX controls. This is especially interesting when you consider that the ActiveForm can be used on a Web page. Next month, in Part II of this series, I will show you how to deploy an ActiveForm on a Web page.
3 of 3
15/06/2012 4:24 PM