Rapid development of ActiveX controls using Delphi

Source: Internet
Author: User
Tags ole

You can use Delphi to quickly develop ActiveX controls to add ActiveX controls to favorites, which are commonly referred to as OCX controls. It is part of ActiveX technology. ActiveX is a technology launched by Microsoft Based on the component object model com, including a series of extensions and enhancements to the Windows 32-bit Application Programming Interface (Win32 API) and Component Object Model, the goal is to integrate the computer desktop environment with the Internet environment and protect existing development investment in Windows technology. Microsoft's ActiveX technology is basically the modified OCX technology that enables it to span the Internet, primarily using WWW to transmit controls. ActiveX controls can be integrated into many applications that support ActiveX, or directly used to extend the functions of applications, activeX-Supported Applications include C ++ builder, Delphi, visual dBase, Visual Basic, Visual C ++, Internet Explorer, and Netscape Navigator. ActiveX controls can also be used on the Internet to publish information on webpages and process interactions with users. However, ActiveX-enabled browsers are required to read these webpages. Currently, more and more ActiveX controls have been developed. Because ActiveX controls have good features, we can choose to use appropriate controls during programming to accelerate application development. ActiveX control is an indispensable magic weapon for programming on Windows platforms. Using ActiveX controls is relatively simple. However, developing ActiveX controls is not a simple task. You must be familiar with ActiveX technology, not just understand ActiveX technology, to develop good ActiveX controls. However, ActiveX technologies such as COM and OLE are complicated and difficult for general programmers. Therefore, ActiveX Control developers are generally programmers at the "laruence" level. However, if you have Borland Delphi of Inprise, it is another matter. As one of the best programming tools on Windows, Delphi provides strong support for ActiveX control development, allowing you to easily develop ActiveX controls. Developers of Delphi can use the tools provided by Delphi to quickly develop their ActiveX controls by simply learning some simple knowledge about ActiveX controls. This article describes in detail how to use the tools provided by Delphi to quickly develop ActiveX controls. 1. To develop ActiveX controls, you must first have a brief understanding of ActiveX controls. In Delphi, an ActiveX control consists of the following components: VCL (visual component library) controls, attributes, methods, events, and one or more related type libraries, each part has its own role. The following describes each part: 1. in Delphi, a vcl component is packaged by one or more VCL components. Therefore, to use Delphi to develop ActiveX controls, you must first develop or select the VCL component to be packaged. For this reason, we can package a large number of excellent VCL components in Delphi into ActiveX controls, these controls can be used in other development tools that cannot directly use VCL components (such as Visual Basic and Visual C ++! However, the VCL component that can be used as an ActiveX control in Delphi must be a descendant of twincontrol. To use a subclass of tgraphicontrol as an ActiveX control, you only need to change its base class to tcustomcontrol in most cases. Some VCL components are registered as non-ActiveX controls, such as editcontrol, which cannot be used as ActiveX controls. 2. The Type Library contains the type definition information of the control and provides more detailed information than the interface. It is a way for the control to provide service information to its host Program. The purpose of the Type Library is to provide information about the component objects it contains for other applications and programming tools. When developing ActiveX controls, Delphi stores the type library information into one. the TLB file and a corresponding Pascal file (. the Pascal language version of The TLB file). The Type Library will be linked to the DLL or EXE as a resource during compilation. The elements of a Type Library include: (1) Type Library Information, including the overall information and features of the Type Library, other types referenced by the current type library, and (2) component class: represents the entire ActiveX control, including the interface provided to the customer application; (3) interface attributes, methods, events; (4) Enumeration type: a constant used as a data type, attributes and methods can be defined elsewhere in the Type Library. Delphi provides a Type Library editor for observing or modifying the Type Library. See figure 1. You can use it to add, modify, and delete various elements of the Type Library. From the interface of Figure 1, we can see that there is a tree structure on the left, and the members of various elements appear as subnodes. The right side shows different tabs Based on the selected element types on the left, you can edit some attributes of this element. 3. attributes, methods, and events of the VCL component are naturally converted into properties, methods, and events of ActiveX controls. Controls, such as colors and labels. Controls are requested to execute certain actions. Events are notifications sent to the Host Program by controls. 4. The property page of the ActiveX control allows the control user to view and modify the properties of the control. You can bind several attributes to one property page or provide only one property page for one property. Ii. quick development of ActiveX controls let's use Delphi to create an ActiveX control. Assume that the problem we are facing is that when using Visual C ++ (VC) to develop an application, we need to use a grid control to process the interface, the use of the FlexGrid Control provided by VC is troublesome, and it is found that the tstringgrid component in Delphi is very suitable. However, tstringgrid is a VCL component in Delphi and cannot be directly used by VC. What should I do? Don't worry, we just need to wrap tstringgrid into ActiveX controls that VC can use to solve this problem. Delphi provides two wizards for ActiveX control development: * ActiveX Control wizard allows you to package a VCL component into an ActiveX control. The Wizard will be used below. * The activeform wizard can encapsulate several VCL components into an ActiveX control or develop a complete ActiveX application. In Delphi, the process of packaging tstringgrid into an ActiveX control is as follows: first, start the ActiveX control wizard, select the new command in the File menu, and select the ActiveX tab in the pop-up dialog box, double-click the ActiveX control icon, as shown in figure 2. The first field in the Wizard requires you to select a VCL component to be packaged, and click Select tstringgrid. Take the default values for the other fields. If you want to include version information and other information, you can also select. Click OK. The Wizard will generate a Delphi ActiveX Control Development Project stringgridxcontrol1, which includes the following files: 1. an ActiveX project file contains the Code required to start and initialize an ActiveX control. This file does not need to be modified. 2. A type library file (TLB extension) defines and implements interfaces, properties, methods, and events provided by ActiveX controls. Delphi provides a Pascal file for this file and automatically maintains the consistency between the two files. 3. An ActiveX implementation file defines and implements the ActiveX control using the Delphi ActiveX framework (Dax), and implements the interface defined in the Type Library. This file needs to be modified frequently. Dax is the method that Delphi implements the com protocol for ActiveX controls. 4. If you select a dialog box that includes "about", there is a corresponding dialog box implementation file. The ActiveX Control Wizard of Delphi generates ActiveX control attributes, methods, and events based on the properties, methods, and events of the encapsulated VCL component. However, it does not convert the attributes, methods, and events of the VCL component using non-ole types (such as collections and arrays. For example, the options attribute of tstringgrid is set type, and rowheights is array type, which is not included in the properties generated by the control wizard. But sometimes these attributes, methods, and events are very important. In this case, you need to manually add some attributes, methods, and events! Add a browselect attribute for this ActiveX control. This attribute is a subattribute of the options attribute of tstringgrid to control whether the grid is selected in rows. In the stringgridxcontrol1 project, open the ActiveX implementation file stringgridimp1.pas and select the add to interface command in the edit menu (Note: This command can be used only when the implementation file is opened ), delphi will pop up the Add interface dialog box, as shown in 3. Select properties/methods-istringgridx for the interface item in the dialog box, and write the declaration of the browselect attribute in Declaration (if you select the syntax helper option in the dialog box, delphi will prompt you the content you should enter at any time): Property browselect: wordbool; click OK, information about this attribute will be automatically added to the control implementation file, Type Library file, and the corresponding Pascal file. Because the control interface is bidirectional, the Pascal file uses the Read and Write methods to implement the control attributes. Delphi automatically adds the following declaration to the Type Library: Property browselect: wordbool read get_browselect write set_browselect; this shows that for the browselect attribute, there is a read method get_browselect and a write method set_browselect. Delphi automatically adds the description and Implementation of the read and write access methods to the browselect attribute in the control implementation file: function get_browselect: wordbool; safecall; Procedure set_browselect (value: wordbool ); safecall; at this time, the implementation bodies of the two methods are empty. You must enter the specific implementation code: function tstringgridx. get_browselect: wordbool; begin // you can write the following code as needed. // you can check whether the current row is selected. With fdelphicontrol do result: = gorowselect in options; end; Procedure tstringgridx. set_browselect (value: wordbool); begin // the following code depends on your needs To write // set the row selection status with fdelphicontrol do begin if value then options: = options + [gorowselect] else options: = options-[gorowselect]; end; at this time, use the Type Library editor to view the type library. You can see the newly added browselect attribute. Similarly, we can add more attributes to ActiveX controls. You can also add new methods and events to ActiveX controls. The addition method is similar to adding properties. In addition, Delphi will automatically add the corresponding method and event declaration and implementation to the corresponding file. The specific implementation body must be compiled by yourself. We can note that Delphi automatically generates the packaging code required to package the VCL component into an ActiveX control. When adding new properties, methods, and events to ActiveX controls, we only need to associate the ActiveX control data with the data of the VCL component in the implementation of interface methods, alternatively, you can use the VCL Component Method to complete ActiveX control behaviors. Basically, you do not need to write the details of an ActiveX control, such as the com protocol. As mentioned above, you can also add custom property pages for ActiveX controls. You do not need to add a new property page here, because most ide programming environments that support ActiveX already provide an attribute page for each ActiveX control by default, we can use this default property page. After completing the preceding work, select the build stringgridxcontrol1 command in the project menu to generate the ActiveX control we need. In the project directory, we can find the stringgridxcontrol1.ocx file. This is our ActiveX control! Copy it to the system directory of Windows 9x or the System32 directory of Windows NT/2000, and then use the regsvr32 stringgridxcontrol1.ocx command to register the stringgridx control in the system, it can be used in VC programming. Iii. Summary thanks to Delphi's strong support for developing ActiveX controls, we quickly got a new ActiveX control without any effort. Delphi allows developers who use it to develop ActiveX controls to focus on the VCL component that serves as the basis of ActiveX controls, without having to care too much about the details of ActiveX controls, therefore, developers who are not familiar with ActiveX technology can also enjoy the fun of developing ActiveX controls, and greatly enrich the controls that can be used in VC and VB development. This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/chenyq2008/archive/2008/01/30/2072596.aspx

 

 

 

Developing ie Control ActiveX (Delphi printing Control) on)

Article category: Java programmingKeyword: ActiveX IE control fastreport has always felt that it is very difficult to develop IE control. It is developed by some senior programmers. It is really hard to develop IE control.

After several days, I checked the information and asked others. I finally made my first IE control, the car e-ticket printing control. Next, follow your own steps to record it, so as not to forget it. I developed it with Delphi7 (I learned it during the design of the school's curriculum, and I never used it again later, hand born), using the fastreport report print control (http://fast-report.com/en/), and Delphi7 webdeploy release tool (http://www.2ccc.com/article.asp? ArticleID = 4381 ):

1,InstallDelphi and plug-ins, because they do not install plug-ins on Delphi, it takes a lot of effort to ask others.

2,Create an ActiveX ProjectI chose "ActiveX form" here. As for other options, I really don't know what it is for development.

3,Develop Delphi ProgramThe next thing is to drag the control and write the code. Debugging is often required. I don't know if there is any good solution. I think it is troublesome to develop ActiveX controls. Therefore, basically, I first write some difficult programs that need to be written multiple times on the common application form, copy it to the "ActiveX form" project (detailed development process of Delphi + fastreport will be discussed below ).

4. UseWebdeploy releasedIn Web deployment options, select the release path. After the release, an HTML file is automatically generated with an OCX control, the code in HTML also needs to be adjusted by yourself. The size, location, and ocx path of the object tag should be changed to the relative path. Otherwise, an access denial error may be reported.

5. Open the HTML with IE and select "blocked content" in the warning to install the control in "C: /Windows/Downloaded Program Files ", if you need to change the code again,DebuggingYou need to right-click and delete it from here (you need to disable this HTML page, otherwise it cannot be deleted)

6. Next, you will think thatIconIt's a little ugly (default icon of Delphi). If you find this in project> Options> application, you won't be able to change it. What should you do. Reference the third floor myy () reply to-10-27 10:28:59 score 30 two methods can be:
1. Use image editor to open the project name. Res file, edit the "mainicon" in it, and save the file.
2. Write a. RC file with the following content:
A_my_icon icon E:/mywork/myocx/My. ICO
Add a home to the project. Note that the name "a_my_icon" is sorted by string,
It cannot be placed behind "mainicon.

7. I will also find a problem. The OCX control I wrote seems to be very large. I used the fastreport control, and ocx has 1550 kb in total.Weight Loss. Then Query Information "http://www.delphibbs.com/keylife/iblog_show.asp? Xid = 19233 ". I seem to mark it as 248k. It's amazing! If you have time, delete the packages one by one. Reference keylife rich notebook
Author: Stake
Title: Step-by-step reduction of your Delphi Program (from 443kb to 34kb)
Keywords: Weight Loss package
Category: personal zone
Confidentiality level: Public
(Score:★, Reply: 5, read: 1654 )»»
Do you think delphi2006 compiled files are all large blocks?
KB, which is really troublesome. In fact, this is because the file contains too many packages. Here we will teach you a way to remove unwanted packages!

Select project-> options... (SHIFT + Ctrl + F11) in the menu)
The project options for project1.exe window appears. Select packages on the left.
If something appears, modify it as follows:
1> hook [] Build with runtime packages in runtime packages
2> remove unnecessary packages. (Generally, you can write Win32 programs as long as RTL; VCL)

If you really don't know which package to go to, you can select a package in the above design packages, click the components button to view the control provided by this package. If you have never used this package, just remove the hooks.

8. AuthenticWeb Applications(I haven't finished it yet. I will make it up later)

The following describes the problems encountered in the development of Delphi + fastreport:
1. fastreport has never been used,Data Query:
Demo: some demos are available in the files downloaded from the official website.
Fastreport Development Guide: http://download.csdn.net/source/573124
A short article: http://www.qq08.net/article/2007/1019/article_26559.html

2. When barcode (bar code control) is used, an error is always reported. In addition to putting barcode in the report, you also need to putFrxbarcodeobjectControl (also mentioned in the fastreport Development Guide ).

3. How aboutSend dynamic code to BarcodeCome in, there's a cool guy here, the answer is really great http://delphi.ktop.com.tw/board.php? Cid = 168 & FID = 916 & tid = 66419

4. Because the English version of fastreport is installed on your own, in the print preview of the control, the interface is in English.Localization?
Compile. In the/RES folder, create a "Chinese" file and put the six source files in it. Run recompile.exe in the fastreportdirectory and select the option to run the compilation.

5. Print the upper left corner of the preview.IconIt's the FR icon. No problem. Change it!
Token (in fact, I searched for three files with the same name. For the sake of insurance, I changed two places that I thought needed)

  • The size is 126.7 kb.
  • The size is 106.3 kb.

 

Due to the needs of the project, I recently began to learn how to use Delphi to develop a softphone control.
I have been familiar with some Delphi development things before (of course, they are all superficial), but I have never been familiar with OCX control development. Here I will write down some simple things, on the one hand, you can learn it again later. On the other hand, you hope to help beginners who have just learned how to develop OCX controls in Delphi. If there is anything wrong with writing or something bad, please correct me more, thank you first.
Some basic knowledge about OCX controls is not mentioned here. There are a lot of articles on the Internet. If you are interested, you can search for them online !!
The integrated development environment of Delphi provides good support for the development of OCX controls. You can develop your own OCX controls in just a few simple steps. Below are some simple steps for Delphi to develop OCX:
1. Open the integrated development environment of Delphi and select File> New> other. A multi-page window is displayed. Select ActiveX page, select ActiveX form, and click OK, in the displayed project property box, set a name for ActiveX so that the project of an OCX control can be created.
2. Save the project
This OCX control is built, but this OCX does not have any functions. However, you can compile this OCX and then publish it on the web, then we can use the browser to call this OCX control. The following describes some simple steps for compiling and publishing:
1. Select project-> compile project (CTRL + F9) A to compile the project
2. register the component: Run-> Register ActiveX Server (Note: After adding a new component to form, register the component again after compilation. Otherwise, the newly added component cannot be displayed)
3. Release: Project-> Web deploy ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.