Mega Code Archive

 
Categories / Delphi / Graphic
 

Design time Icons for CoClasses

Title: Design time Icons for CoClasses Question: This article describes how to add a icon to a CoClass. The Icon will be shown in Programming enviroments like VB, VC++, Delphi, ... Answer: To add a icon to a Coclass, there must be a special key in the windows registry. see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/reg_14z6.asp for more info. We can do this automatically, if we use the following factory: TAutoObjectFactoryWithIcon = class(TAutoObjectFactory) private FIconIndex: Integer; public procedure UpdateRegistry (bRegister: boolean); override; property IconIndex:Integer read FIconIndex write FIconIndex; end; implementation procedure TAutoObjectFactoryWithIcon.UpdateRegistry(bRegister: boolean); var BitmapKey: string; begin BitmapKey := 'CLSID\' + GUIDToString(ClassID) + '\ToolboxBitmap32'; if bRegister then begin inherited; CreateRegKey(BitmapKey, '', ComServer.ServerFileName + ',' + IntToStr(FIconIndex)); end else begin DeleteRegKey(BitmapKey); inherited; end; end; The next thing, we have to do is to replace the factory class: initialization with TAutoObjectFactoryWithIcon.Create(ComServer, TMyCoClass, Class_MyCoClass, ciMultiInstance, tmApartment) do begin IconIndex := 3; end; end. And don't forget to add a icon (16*16 Pixels) for every CoClass to the ActiveX-DLL or Automatisation-Server. please refer to: http://www.delphi3000.com/articles/article_2606.asp