Michel Brazeau
Posts: 17
Joined: 2006-08-31
|
Hi All,
I created a simple addin that adds a command bar to word/excel/outlook.
One or more button is added to the command bar based on a configuration file.
The command bar and buttons are added programmatically in TAddInModule.Create.
For some strange reason, sometimes users end up with duplicate copies of the command bar buttons. For example, if there is suppose to be only one button, the button is duplicated 3 times on the command bar, but on one button responds to the event properly.
Sometimes unregistering/registering the DLL solves the problem. Sometimes toolbar has to be reset in word.
Below is the code that creates the command bar and buttons.
Anyone have ideas why this can happen?
Michel
----
code below
constructor TAddInModule.Create( AOwner : TComponent );
var
OutlookButton : TAdxCommandBarButton;
WordButton : TAdxCommandBarButton;
ExcelButton : TAdxCommandBarButton;
Bitmap : TBitmap;
Index : Integer;
begin
inherited Create(AOwner);
FDeleteEmailAfterSend := False;
FDeleteDocumentAfterSend := False;
FEditMetaData := True;
FExcelCommandBar := nil;
FWordCommandBar := nil;
FOutlookCommandBar := nil;
FConfig := TEdmCfgFile.Create;
Self.OnAddInFinalize := Self.ModuleFinalize;
Self.OnAddInInitialize := Self.ModuleInitialize;
Self.OnOLExplorerFolderSwitch := Self.ModuleExplorerFolderSwitch;
Self.OnOLExplorerSelectionChange := Self.ModuleExplorerSelectionChange;
if FConfig.Count > 0 then
begin
FOutlookCommandBar := TadxOlExplorerCommandbar.Create(Self);
FOutlookCommandBar.CommandBarName := 'EDC';
FOutlookCommandBar.SupportedApps := [ohaOutlook];
FOutlookCommandBar.Protection := adxMsoBarNoChangeVisible;
FOutlookCommandBar.Position := adxMsoBarTop;
FWordCommandBar := TadxCommandBar.Create(Self);
FWordCommandBar.CommandBarName := 'EDC';
FWordCommandBar.SupportedApps := [ohaWord];
FWordCommandBar.Protection := adxMsoBarNoChangeVisible;
FWordCommandBar.Position := adxMsoBarTop;
FExcelCommandBar := TadxCommandBar.Create(Self);
FExcelCommandBar.CommandBarName := 'EDC';
FExcelCommandBar.SupportedApps := [ohaExcel];
FExcelCommandBar.Protection := adxMsoBarNoChangeVisible;
FExcelCommandBar.Position := adxMsoBarTop;
end;
for Index := 1 to FConfig.Count do
begin
OutlookButton := FOutlookCommandBar.Controls.Add(adxButton) as TAdxCommandBarButton;
OutlookButton.Caption := FConfig.GetDictStr(CSendTo) + ' ' +
FConfig.Items[Index].EdmName + ' (' + CVersionStr + ')';
OutlookButton.OnClick := Self.SendToEDCFromOutlook;
OutlookButton.Tag := Index;
WordButton := FWordCommandBar.Controls.Add(adxButton) as TAdxCommandBarButton;
WordButton.Caption := FConfig.GetDictStr(CSendTo) + ' ' +
FConfig.Items[Index].EdmName + ' (' + CVersionStr + ')';
WordButton.OnClick := Self.SendToEDCFromWord;
WordButton.Tag := Index;
ExcelButton := FExcelCommandBar.Controls.Add(adxButton) as TAdxCommandBarButton;
ExcelButton.Caption := FConfig.GetDictStr(CSendTo) + ' ' +
FConfig.Items[Index].EdmName + ' (' + CVersionStr + ')';
ExcelButton.OnClick := Self.SendToEDCFromExcel;
ExcelButton.Tag := Index;
Bitmap := nil;
try
if FConfig.Items[Index].SendToBmpFileName <> '' then
begin
Bitmap := TBitmap.Create;
Bitmap.LoadFromFile(FConfig.Items[Index].SendToBmpFileName);
end
else
Bitmap := LoadBitmapFromExeRes( 'MOVETOFOLDERBMP' );
OutlookButton.Glyph := Bitmap;
WordButton.Glyph := Bitmap;
ExcelButton.Glyph := Bitmap;
finally
Bitmap.Free;
end;
end;
end;
|
|
Dmitry Kostochko
Add-in Express team
Posts: 2880
Joined: 2004-04-05
|
Hi Michel,
Could you please send me your project (or some test project with the same behavior) for testing?
|
|
Michel Brazeau
Posts: 17
Joined: 2006-08-31
|
Hi Dmitry,
I was able to create a small test project where the problem is occuring.
I will email you directly with attachment.
Thanks,
Michel |
|
Dmitry Kostochko
Add-in Express team
Posts: 2880
Joined: 2004-04-05
|
Hi Michel,
I have just fixed your project and sent it to you.
|
|