Delphi XE7 to develop ActiveX and debug under Intraweb

Source: Internet
Author: User

Recently learning DelphiXE7 under the Intraweb development, Intraweb full server-side operation so that Fastreport report system can not run on the client, of course, there are a lot of solutions on the Internet, such as export to PDF, give the connection, let customers click Download, etc. Personal feeling is not perfect. Because I do the b/s system mainly run on the Windows platform, so still consider the ActiveX plugin, come intuitive.
First, DelphiXE7 under the development of ActiveX

1, new-other-Open the window, select the ActiveX Library, click the OK button

2, the appearance of such an interface, at this time, Delphi set up a windowless frame, generating 3 units: _tlb,.ridl and engineering documents

3. Click the New Item button and select the first active Form to click OK

4, at this time Delphi for us to establish a window, here is where we want to implement the function of the place, I added in this window ADO connection, Adodataset, report control and a button, window name I named Pgform

5. Add properties and methods for our ActiveX plugin: Click Ridl Unit in Ipgform, right click on the interface section of this ActiveX form, pop-up menu, here can add new interface, properties, methods, data module, etc.

6, pay attention to the Type property of the right inside to choose a BSTR (Delphi inside the Widestring), click on the Refresh button above, Delphi will automatically add this property in Unit1 inside the framework of the implementation method

Here, I will name this newly added attribute SQL and add a private member _sql to save this property value in the private part of the form. At the same time with the same method, I add a method shows, at this time can implement this shows method, complete a certain function. This property and method can be called by Intraweb, followed by calls to invoke how to invoke the

7, in the _tlb unit to find the GUID of this form (there are many GUIDs in this unit, remember that is the form, not the other), this GUID is very important, in the following intraweb inside the call to use the ActiveX. In this case, the bottom one is the guid,class_pgform:tguid=xxxxxxxxxxxxxxx.

8, the above properties and methods to complete the function, you can save the project, and then compile and build the OCX file


Second, call ActiveX in Intraweb

1, the new Intraweb project will not say, add a Iwactivex control in the window, this control is used to load our ActiveX

Here the main set of two properties: one is the ClassID property, the second is the CodeBase property, ClassID is the one we mentioned above the guid,codebase is to load the OCX file name, in this case I used a cab control price package. /files/zz.cab, where the first forward slash/represents the folder where our DLL file is located (or the Wwwroot folder), the Files folder behind it and our DLL file in the sibling folder, when the user browses the page, the browser prompts to install the ActiveX control , select Install.
Key content: Intraweb calling Methods in ActiveX
I wrote the following code in Iwform's OnRender event, and of course it can be written elsewhere, such as OnCreate, in order to add JavaScript code to the JavaScript properties of Iwform. The code for this example is to find the ActiveX object in the Web page by ID, assign its property SQL, and call its method SHOWRP (which says shows, the name is different), the code of the string part conforms to the JavaScript syntax, not the Delphi syntax. In this example, we define a JavaScript function that calls the properties and methods of our ActiveX control, in fact, the access to ActiveX in Intraweb, regardless of the intraweb, is completely JavaScript control ActiveX, said The Iwactivex control is only responsible for inserting ActiveX objects into our web pages in JavaScript language, which does not access ActiveX and can only access ActiveX objects with JavaScript.

This JavaScript function repprint () is then called in the Scriptevents attribute of the Iwbutton.

This is what the Iwactivex control above does, inserting an ActiveX control in the JavaScript language, and he can't do the rest.

Let's talk about how to create a cab and signature

Iii. creating a cab and signing

1. Create a cab
Create a CAB package with Windows IExpress, and in the start, run input IExpress the following window appears

Choose Create New and click Next

To select the bottom option, create a self-extracting cab in the ActiveX installation format and click Next

Here, click on the Add button to select the OCX file that we just compiled, click Next

Click Browse folder Here, select the location and file name you want to save, and tick the bottom check box, meaning to save a long file name

This window means, whether to save this cab temporary file for later editing, here I chose not to save, and then click on the next step to complete
2. Create certificates and signatures
First download a SignTool signature tool Http://www.pfeng.org/tools/signtool.rar
Then, in the cmd command window, type:
makecert -sv printocx.pvk -r -n "CN=KeHong Company"printocx.cer
这里的
"CN=KeHong Company" is the signature name can be arbitrarily changed, PVK is a password file, CER is a certificate file, of course, you can specify the file name

After clicking the Enter key, a window will appear asking for the password, which will appear three times, please enter the same password

When you are sure, the certificate is created.

3. Sign our CAB control package with this certificate
In our Download SignTool toolkit There is a signature tool Signcode.EXE, run it

Click Next to select the CAB control package we just built, I chose OCX here, the method is the same, next

To choose Custom, you can select the CER certificate file we just created in the next procedure

Click Select from file, pop-up window, select the CER certificate file we just created and click Next

This requires selecting the password file, which is the same pvk file that we generated when we created the certificate, click Next

Then enter the password set when creating the certificate, click OK

Choose a cryptographic algorithm, click Next

Click Next directly

Click Next, ask to enter the password when entering the password, complete

Iv. Installation of certificates
The above describes the ActiveX development, CAB packaging, certificate creation, signing and calling ActiveX in Intraweb, which is actually very simple.
Is that the way it must be? Not necessarily! Since our cab signature is not issued by a trust authority (it is said that the annual fee for a certificate issued by a trust agency is $400), it is also necessary to install the CER certificate of the signed CAB control package into the trusted root certificate zone, otherwise the browser may prevent the installation of our ActiveX plugin.
When the browser block our plugin (client), will pop up a window, there is a "publisher" can click, and then you can view the plugin signed certificate, click to view the certificate, the following window appears

Click Install certificate and select the second option to specify a location to install

Click the browse button, the selection of the installation location of the certificate, in order to select "Trusted Root certification Authority" after the successful installation, IE load our ActiveX control again, prompt installation, click Install.

V. Control of the OCX control version

Once the same ClassID ActiveX control is registered to the client machine, each browser that supports the OCX control will automatically load.
But what if our OCX control is upgraded and the client is still using an older version of the OCX control? Not always manually delete the registered controls on the client computer? The solution is the OCX version control: At the same time to change the OCX control file version and Intraweb in the Iwactivex codebase version number can achieve this goal (the two version number must be the same, or the client every time the page refresh, you have to install the control, very annoying OH)

1. Change the file version number of the OCX control
In the above example of the ActiveX development, before compiling to OCX, click Project-options Open the dialog box, find the version page, you can see the file revision number settings, as shown in
The major version number defaults to 1, and the default is 0, which changes the version number. Here, I changed the main version number to 4, compiled to generate OCX

2. Change the version number in the codebase in Intraweb

In this example, the ActiveX call mentioned above, codebase without version number, here we use the method shown below, plus the version number. #version =4,0 means, let the client browser when calling this OCX, check whether the registered OCX version is 4, 0, if it is called, or re-download the installation. Note that there is a comma in the middle of the 4,0, not a period!
OK, recompile this DLL, overwrite the Web site root, open this page to try, the browser will prompt to re-download the control and install.

Delphi XE7 to develop ActiveX and debug under Intraweb

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.