|
|
|||
Home Products Downloads Registered users Support Prices Order Primary Subscription |
|
||
AddXXX methods and NewControl parameterAll 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;
begin
IsNew: boolean; ICBox: IaxpComboBox;
inherited;
end;
AddCmdBar(BarName, IsNew); ICBox := AddComboBox(BarName, 'Country:', cbCountryTag,
'Select country', msoComboLabel, true, IsNew);
if IsNew then begin // <==== !!!
DM := TDataModule1.Create(nil);
end;
try
DM.Table1.Active := true;
finally
ICBox.Clear; while not DM.Table1.EOF do begin
ICBox.AddItem(DM.Table1.FieldByName('Name').AsString,
end;
EmptyParam);
DM.Table1.Next;
DM.Free;
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;
begin
isNew: boolean;
IPopup := AddPopup('My Bar', 'My Popup', 'MyPopupTag',
end;
'This is My Popup', IsNew);
IPopup.Width := 200;
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;
begin
isNew: boolean;
IPopup := AddPopup('My Bar', 'My Popup', 'MyPopupTag',
end;
'This is My Popup', IsNew);
if isNew then
IPopup.Width := 200;
Once-only initialization should be done only once! (c Author) And your helper is the NewControl parameter. |
Developed forDelphi 5, 6, 7
[ Download it ] Immediate shipment
|