Microsoft Excel reporting and 
 data analyzing with practically no coding. 
 .Net, ActiveX, and VCL versions. 
 www.AfalinaSoft.com  

Home    Products    Downloads    Registered users    Support    Prices    Order    Primary Subscription

 

MS Office COM Add-ins. Microsoft Excel reporting 
 and data analyzing


Source code review - Office Add-in Express Developer's Guide

<< Previous

Table of contents

Next >>


Step #2 - Source code review

First of all, in the initialization section you can see a call of the specialized class factory that is supplied with Add-in Express.

TaxpFactory.CreateEx(ComServer, TMyFirstAddIn, Class_MyFirstAddIn,
[ohaExcel], 'First COM Add-in',
'The first COM add-in for MS Excel that is being designed through Add-in Express');

The parameters of TaxpFactory.CreateEx differ from the standard factory constructor (TAutoObjectFactory.Create). For instance, the [ohaExcel] set specifies a COM Add-in for MS Excel only. You can add to this set other constants, say, ohaWord or ohaOutlook, right now. The next two parameters are the name and the description of your COM Add-in.

An add-in usually shows itself in one or more buttons on Office application's toolbars or in one or more menu items. The best place for adding toolbars and buttons is the TaxpAddIn.AddIn_Initialize method, which is usually overridden in descendant classes.

type
TMyFirstAddIn = class(TaxpAddIn, IMyFirstAddIn)
protected
{ Protected declarations }
procedure AddIn_Initialize; override;
end;

implementation

uses ComServ;

{ TMyFirstAddIn }

procedure TMyFirstAddIn.AddIn_Initialize;
var
IsNew: boolean;
begin
inherited;
AddCmdBar('My Bar', IsNew);
AddButton('My Bar', 'My Button', 'MyBtnTag',
'This is my button', '', msoButtonCaption, IsNew);
end;

First of all, we call the AddIn_Initialize method of the ancestor class (the inherited; clause). Then we add a new toolbar (or, CommandBar in MS terms) called My Bar. And finally, we add a button (CommandBarButton) whose caption is "My Button", tag is "MyBtnTag", and hint is "This is my button". The empty string in parameters of the AddButton method indicates that this button has no icon. The msoButtonCaption constant specifies the style of the button. The IsNew parameter is described in "AddXXX methods and NewControl parameter" below.

Note: CommandBarControl.Tag
The more correct way of using tags is previously defined constants. For instance we should define the constant MyBtnTag = 'MyBtnTag' and use it whenever identification by Tag is needed.

Now, we can check if our COM Add-in is working correctly. Choose Run|Register ActiveX Server. The server being registered, you should start MS Excel. Hope you succeeded in finding your first COM Add-in. <g>


Unfortunately, "My Button" doesn't produce any actions. Seems, this is the only thing that remains.

Add-in Express processes all events of all controls in the TaxpAddIn.AddIn_ControlEvent method that you should override in a descendant class. Look how this method is implemented in your first Add-in:

type
TMyFirstAddIn = class(TaxpAddIn, IMyFirstAddIn)
protected
{ Protected declarations }
procedure AddIn_Initialize; override;
procedure AddIn_ControlEvent(const Tag: string; ICtrl: IaxpControl); override;
end;

...

procedure TMyFirstAddIn.AddIn_ControlEvent(const Tag: string;
ICtrl: IaxpControl);
begin
if Tag = 'MyBtnTag' then
ShowMessage('Hmm... I click my button!');
end;

Add-in Express identifies all its controls (CommandBarControl) through the use of the Tag property. Note, that Microsoft uses strings and not integers in Tag. The second parameter of the method is the reference to the CommandBarControl interface, which you can use in order to change the control's appearance or to get its value, for instance. In our sample we just show a message. Do you get it? <g>

In Microsoft Office applications, there are three kinds of CommandBar objects: toolbars, menu bars, and pop-up menus. Pop-up menus are displayed in three ways: as menus that drop down from menu bars, as submenus that cascade off menu commands, and as shortcut menus. Shortcut menus (also called "right-click menus") are menus that appear when you right-click something.

Note: CommandBars and CommandBarControls
CommandBar and CommandBarControl are interfaces to appropriate MS Office controls. They are described in the imported type libraries included into Delphi and named Excel2000.pas, Word2000.pas, Outlook2000.pas, Access200.pas MSPPT2000.pas. Add-in Express contains some additional type libraries for MS Project 2000 and FrontPage 2000 that can be found in the \Source subfolder of the Add-in Express installation folder. They correspond to the Office 2000 suite and can be used with Office 2002 (XP).

Add-in Express redeclares some of the interfaces in the axpAddIn unit. These interfaces have the Iaxp prefix. We cannot describe all the interfaces of the CommandBar and CommandBarControl group here. Please refer to the VBAOFF9.CHM (Office 2000) file and to the imported type library in axpOffice.pas.

<< Previous

Table of contents

Next >>



Developed for

Delphi 5, 6, 7
Excluding Delphi Personal


[ Download it ]

[ Order now ]

Immediate shipment




ADX Toys™

Free sample
add-ins with a complete source code based on Add-in Express.

[  Read more  ]




We are Borland 
 technology partner


Copyright © 1999-2006
All right reserved.
Privacy Policy

Write to WebMaster

Page Top
Add-in Express - COM Add-ins, Smart Tags and RTDS in C#, VB, C++, J#, and Delphi