|
|
|||
Home Products Downloads Registered users Support Prices Order Primary Subscription |
|
||
Step #2 - Source code reviewFirst 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 }
end;
procedure AddIn_Initialize; override; implementation uses ComServ; { TMyFirstAddIn } procedure TMyFirstAddIn.AddIn_Initialize; var
IsNew: boolean;
begin
inherited;
end;
AddCmdBar('My Bar', IsNew); AddButton('My Bar', 'My Button', 'MyBtnTag',
'This is my button', '', msoButtonCaption, IsNew);
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 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 }
end;
procedure AddIn_Initialize; override; procedure AddIn_ControlEvent(const Tag: string; ICtrl: IaxpControl); override; ... procedure TMyFirstAddIn.AddIn_ControlEvent(const Tag: string;
ICtrl: IaxpControl);
begin
if Tag = 'MyBtnTag' then
end;
ShowMessage('Hmm... I click my button!');
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 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. |
Developed forDelphi 5, 6, 7
[ Download it ] Immediate shipment
|