|
|
|
Ensuring your Classes are Registered
One of the things I've noticed when developing applications reliant on
third party COM components is that the effort required to ensure
those components are installed properly can be a tedious task and is more
often than not commonly overlooked.
This is especially true of distributed COM applications that must
ensure all distributed components have their classes registered on not
just the server, but on all client machines as well. Some
developers work around this by stating that their product requires
another product to be installed beforehand in order for their software to
work, avoiding building into their application the simple piece of logic
that goes and checks the for existence of that software.
The
AxRegistration unit contains three methods that make checking for the
existence and registration of COM classes and type libraries easier. They
are:
|
| ComClassesRegistered |
| The ComClassesRegistered method
checks whether a list of classes (identified by their Class ID)
has been registered on the current machine. This includes a
check of the registry and whether or not each class has an
associated type library registered against it.
The function returns false if at least one of
the classes listed in the ClassList parameter is not
registered, and fills the UnregisteredClassList parameter with
the complete list of classes found not to be registered. The
function returns true if all classes have been be registered.
Method Definition
function
ComClassesRegistered(const ClassList: array of
TCLSID;
var UnregisteredClassList: TClassIdArray): Boolean;
Example
uses
Dialogs, ActiveX, AxRegistration;
procedure CheckInternetExplorerRegistered;
var MissingClasses: TClassIDArray;
i: Integer;
begin
if not ComClassesRegistered([CLASS_InternetExplorer,
CLASS_WebBrowser],
MissingClasses) then
for i := Low(MissingClasses) to
High(MissingClasses) do
ShowMessage('Class
' + GuidToString(MissingClasses[i]) +
' is not
registered on this machine.');
end;
|
|
|
|
TypeLibrariesRegistered |
| Similar to the
ComClassesRegistered method, above, the TypeLibrariesRegistered
method checks whether or not a list of type libraries has been
registered on the current machine, and that each type library
can actually be loaded. Each type library presented to this
function is identified by it's type library GUID, and the major
and minor version numbers of that library.
The function returns false if at least one of
the type libraries listed in the TypeLibList paramater is not
registered, and fills the UnregisteredTypeLibs parameter with
the complete list of type libraries found not to be registered.
The function returns true if all type libraries have been
registered and can be loaded.
Method Definition
function
TypeLibrariesRegistered(const TypeLibList: TTypeLibArray;
var UnregisteredTypeLibs: TTypeLibArray; const LanguageCode:
LCID = 0;
const FailOnLanguageCodeMismatch: Boolean = False): Boolean;
|
|
|
| RegisterTypeLibrary |
| The RegisterTypeLibrary method
is used to register type library ALibraryFileName on the
current machine. ALibraryFileName can represent a physical COM
server (such as an EXE, DLL or OCX), or can be a type library
definition file only (such as Delphi's TLB). Because this
function can register type library definition files it is
particularly useful for automated registration of class
information on client machines for distributed COM (DCOM)
applications. If the type library
ALibraryFileName cannot be loaded or registered, this method
throws an exception identifying whether the error occurred on
the load or registration of the type library, and contains the
OLE error code associated with the failure.
Method Definition
procedure
RegisterTypeLibrary(const ALibraryFileName: WideString); |
|
The only caveat of this code is that on NT oriented
platforms, you must have administrator privileges for proper registry
access, otherwise these functions might fail due to access problems.
Requirements
- Delphi 6
- Administrator Access on the Client Machine
Download Code
AxRegistration.pas can be downloaded
here.
|