Delphi Depth Exploration - ActiveX Controlled ActiveX Control

zhaozj2021-02-08  275

Delphi Depth Exploration - ActiveX Controlled ActiveX Control

The powerful database development feature is undoubtedly a pearl on the Delphi crown, with at least 80% of people using Delphi to develop database programs every day. Based on the building block VCL database control, as well as companies provided by companies such as DEV Express and Woll2Woll, there is no exaggeration to set up attributes simply, dragging a few mice we can complete the database very quickly. Development of procedures. Since Delphi's database function is too strong, many people ignore a fact that ActiveX can also provide flexible database binding, unfortunately, there is no one in the ActiveX control provided by Delphi itself. Controls, this indirectly causes a misunderstanding that many people mistakenly think that Delphi does not support data-clear ActiveX controls (including me a long time ago J). This is of course a mistake.

ActiveX controls used in Delphi

In the following example, we will use the Microsoft Calendar 9.0 control that is installed into the system with Office 2000, which is a data clear control. Select Component | Import ActiveX Control, select Microsoft Calendar 9.0 (see Figure 1.12 below), change the class name from Tcalendar to TaxCalendar to avoid conflict with the original same name control in the system, then click the Install button to install this control.

Figure 1.12

Create a new program, place a TaxCalendar control on the form. Plant a DataSource and Table control. Set DataSource's DataSet to Table1, then set the table1 DatabaseName property to dbdemos, the tablename property is EMPLOYEE.DB, and finally set the table1.active property to TRUE.

Next, the database is bound, pay attention to the introduced TaxCalendar has different properties of DataSource and DataBindings, because ActiveX IMPORT WIZARD is introduced to the ActiveX control first, if it is a control, if It is inherited as the base class as the base class, and if not, it will start from Tolecontrol. TDBolecontrol implements DataBindings and DataSource properties. Set the Axcalendar1.dataSource property to DataSource1.

At this time, we right-click the TaxCalendar control on the form, and you will find more than one DataBindings ... menu item in the right mumpu (see Figure 1.13).

Figure 1.13

After clicking on the menu item, the data binding property edit box is displayed (see Figure 1.14 below). Select Hiredate in the fieldName list box, select Value (12) in the Property Name list box, and Click the BIND button to create data association between the database field and the VALUE property.

Figure 1.14

Finally, place a DBGRID and DBNAVIGATOR control on the form and set their DataSource to DataSource1. When running the program, when you move the current data location, you can notice that ActiveX date display will change, and consistent with the HIREDATE in the database. As shown in Figure 1.15:

Figure 1.15

Create a data clear ActiveX control

Although we have clearly used the ActiveX control of Delphi, then a new problem is generated. Can Delphi itself can create a data-clear ActiveX control? Since Delphi provides a step-by-step ActiveX control conversion generation, many people want to convert powerful database controls in Delphi to ActiveX controls so that they can still enjoy like Delphi when developing database programs in other support ActiveX development. Easy and pleasant feelings. However, I have already mentioned in the first part of the previous section. Since Delphi's data, the control is too large on the internal mechanism of the control with the ActiveX database control, so Delphi cannot simply convert its powerful database controls. So, do you like any way? Of Course NOT! In fact, use the type library editor, we can do very easy to implement the data-clear ActiveX control, let us use the TEDIT control to see how to do it. NEW Menu Command New | ActiveX | ActiveX Control Launches ActiveX Control Convert Wizard, select the TEDIT control as a transformation object, generate an EditX ActiveX framework.

Next, we will transform the TEXT attribute to support the data binding. Select View | Type Library to check the type library generated by Delphi and select the text property, then switch to the Flags property page (see Figure 1.16 below).

Figure 1.16

Note that there are many boxes in the Flags property page, for us, only care about the options related to data binding. They are Bindable, Display Bindable, Default Bindable, ImMediate Bindable, and Request Edit options.

After tagging a property is bindable, and then bind it with the database field, when the user modifies the property, the control will notify the database value has changed, and request the database record update status. The database will also notify whether the record update is successful. .

The Bindable option indicates that the property supports the data binding. If the property is tagged as bindable, the property will notify its container when its value changes.

Request EDIT indicates that attributes support the OnRequestedit notification message, which allows the control to ask if the container property value allows users to modify.

Display Bindable indicates that the container can display this property to the user to be bound.

Default Bindable indicates that it is unique, default boreable properties, using it must mark the bindable property at the same time.

Immediate bindable When tagged, all changes will be notified and the Bindable and Request Edit tags are required.

Below we mark the Text property of the EditX control is Bindable, Display Bindable, Default Bindable, and Request Edit. Then click the Refresh button to refresh the type library, and finally select the Run | Register ActiveX Server registration ActiveX control.

Introducing a new EditX ActiveX control, it will find that it does implement the function of the data binding. Here is a program of the program of the program that uses the data clear EditX 1.17, (Delphi's ActiveX data clear function is simple and very simple) No?

Figure 1.17

转载请注明原文地址:https://www.9cbs.com/read-789.html

New Post(0)