Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
Member Area
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Become a Member
-Why sign up!
-Chat Online!
-Indexes NEW!!
-Build your resume
-Find a job
-Post a job
-Resume Search
-Link to us
Visit Embarcadero
Embarcadero Community
How to register an ActiveX library at runtime and create the corresponding Activ Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Delphi 3.x
User Rating
No Votes
# Votes
DSP, Administrator
Reference URL:
			Author: Tomas Rutkauskas

I want to write a client application which, when it starts, scans a given directory 
for ActiveX Form OCX's. If found, I want each ActiveForm to be loaded into the 
interface. This forms a modular plug-in style interface. Can anyone give me some 
advice on how to (register?) invoke and create an ActiveForm given just an OCX.


The steps are:

Runtime registration of the ActiveX library
Runtime creation of the ActiveX control
Invoking methods

1. Registration of the ActiveX library

The code can be found in the source code of the TRegSrv project 
(Delphi4\demos\activex\tregsrv). The crucial steps are listed below (this is a 
procedure that I'm using myself. Could be that you will have to look for the units 
to include).

1   type
2     TRegProc = function: HResult; stdcall;
4   procedure RegisterActiveXControl(Name: string; Extension: string);
5   {name is the name of the ActiveX control, Extension is 'ocx' or 'dll'}
6   var
7     LibHandle: THandle;
8     FileName: TFileName;
9     RegProc: TRegProc;
10  begin
11    {don't mind the path, use your own filename of your own ActiveX control}
12    FileName := 'C:\Temp\PAx' + Name + '.' + Extension;
13    {this line gets a handle to the ActiveX library}
14    LibHandle := LoadLibrary(PChar(FileName));
15    {prepares the registration}
16    @RegProc := GetProcAddress(LibHandle, 'DllRegisterServer');
17    if (not (@RegProc = nil)) then
18    begin
19      {this line executes the registration procedure, if the file is a correct 
20  ActiveX library}
21      RegProc;
22    end;
23    {afterwards, the handle to the file is destroyed}
24    FreeLibrary(LibHandle);
25  end;

2. Runtime creation of the corresponding ActiveX control

You need the following, in a procedure, function or method:

26  var
27    AxControl: OleVariant;
28  begin
29    AxControl := CreateOleObject(AxName);
30    {in which AxName is something like 'AxLibraryName.AxControlName' (cf. 
31  'Word.Basic'). You can find this AxName in the ProgID section of the registry}
32    Result := AxControl.Execute(a, b); {Execute is a method of the AxControl}
33  end;

Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10


Share this page
Download from Google

Copyright © Mendozi Enterprises LLC