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


AddXXX methods and NewControl parameter - Office Add-in Express Developer's Guide

<< Previous

Table of contents

Next >>


AddXXX methods and NewControl parameter

All MS Office applications save the current state of toolbars and menu at the end of session. This quite a reasonable feature constantly induces the user to organize and re-organize its workplace. Add-in Express solves most of the end-user related problems but you should be aware of them. Add-in Express tracks move of toolbars and controls. It organizes "routing" of their events. You can be sure that it saves all controls' properties even a combo's list elements.

That's why controls are not created anew even when AddXXX methods are called in AddIn_Initialize whenever an add-in is run. Each of the AddXXX methods seeks the control having specified Tag in all the toolbars and menus of the host application. The control will be created anew if (and only if) it is not found during the search.

To prove this, we edit AddIn_Initialize in MySecondAddIn:

procedure TMySecondAddIn.AddIn_Initialize;
var
DM: TDataModule1;
IsNew: boolean;
ICBox: IaxpComboBox;
begin
inherited;
AddCmdBar(BarName, IsNew);
ICBox := AddComboBox(BarName, 'Country:', cbCountryTag,
'Select country', msoComboLabel, true, IsNew);
if IsNew then begin // <==== !!!
DM := TDataModule1.Create(nil);
try
DM.Table1.Active := true;
ICBox.Clear;
while not DM.Table1.EOF do begin
ICBox.AddItem(DM.Table1.FieldByName('Name').AsString,
EmptyParam);
DM.Table1.Next;
end;
finally
DM.Free;
end;
end;
end;

You see that the combo's list is created only once. This is not a good example, nevertheless, because it isn't suitable to freeze DB data in the control. The more usual way is to check if the control is created anew. The NewControl parameter of every AddXXX method is intended for use in such situations. For example:

var
IPopup: IaxpCmdBarPopup;
isNew: boolean;
begin
IPopup := AddPopup('My Bar', 'My Popup', 'MyPopupTag',
'This is My Popup', IsNew);
IPopup.Width := 200;
end;

Here the button with popup menu of 200 pixels width is created. But if the user customizes the width, he/she will not get it when reopening the host application. To solve the problem use the NewControl parameter as follows

var
IPopup: IaxpCmdBarPopup;
isNew: boolean;
begin
IPopup := AddPopup('My Bar', 'My Popup', 'MyPopupTag',
'This is My Popup', IsNew);
if isNew then
IPopup.Width := 200;
end;

Once-only initialization should be done only once! (c Author) And your helper is the NewControl parameter.

<< 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