Mega Code Archive

 
Categories / Delphi / Examples
 

Registering a Type Library

Title: Registering a Type Library Question: How do I register a .tlb file for a COM object from within my application, as opposed to having to use the TRegSvr utility? Answer: The following code will register any type library, provided you supply the filename. uses ActiveX, SysUtils, COMObj; procedure TfrmLogin.RegTypeLibrary( Const FileName: String ); var wFileName: WideString; DocName: WideString; TypeLib: ITypeLib; begin if not( FileExists( FileName ) ) then Raise Exception.Create( 'Type library not found' ); wFileName := FileName; OleCheck( LoadTypeLib( PWideChar( wFileName ), TypeLib ) ); OleCheck( TypeLib.GetDocumentation( -1, nil, nil, nil, @DocName ) ); DocName := ExtractFilePath( DocName ); OleCheck( RegisterTypeLib( TypeLib, PWideChar( wFileName ), PWideChar( DocName ) ) ); end;