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.
--------------------------------------------------}
{-------------------------------------------------