Automatically register ActiveX controls while the program is running

Source: Internet
Author: User

When you write a Delphi application, you often encounter ActiveX controls [note: The type library of a control or DLL that has an OCX extension], which provides a simple way of doing the development of your application. However, these programs face the problem of ActiveX control registration while they are being published.

Solution: First, with the installation program to make packaging files, often to increase the size of the program itself, the system reinstall, you must re-install it; second, use the program itself for the form of code writing functions to deal with it.

There are two ways to use these methods:

First, directly to the visual ActiveX control into the program;

Second, the runtime according to the need to establish real-time.

If used directly, the application automatically looks for and creates the ActiveX control that is required during initialization, and if the control is not registered, the initialization program generates an exception to catch and handle the exception.

Add a new method to the program form:

Unit Uautoregactivex;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, comobj; Add Comobj Unit
Type
Tautoregactivexfrm = Class (Tform)
Procedure Formcreate (Sender:tobject);
Private
{Private declarations}
Public
{Public declarations}
Protected
{Public declarations}
Procedure Checkexception (Sender:tobject; Eabort:exception);
End
Var
AUTOREGACTIVEXFRM:TAUTOREGACTIVEXFRM;
Implementation
{$R *.DFM}

{-------------------------------------------------

In standard ActiveX controls, there are two functions DllRegisterServer, DllUnregisterServer callable, where functions are used to register controls to unload controls. We can use LoadLibrary to load dll/ocx files, GetProcAddress get DllRegisterServer and DllUnregisterServer two function pointers, You can then run these two functions directly to implement the procedure for registering and uninstalling ActiveX controls, thereby replacing the Windows system's RegSvr32.exe to implement the registry and uninstall of ActiveX controls.

--------------------------------------------------}

{-------------------------------------------------

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.