Ralf Garbe
Posts: 20
Joined: 2014-11-22
|
Andrei,
we had this topic already in December 2014: https://www.add-in-express.com/forum/read.php?FID=1&TID=12851
The code we worked out worked most of the time, however I have a customer who complains that my Add-in is crashing Outlook, when the user is moving an unread MailItem from the Inbox to another folder. For already read emails (not in bold subject) there is no problem. (on my testsystem I cannot replicate the error)
Could you advise where the below descibed error might come from?
Thanks,
Ralf
- Outlook Version: OUTLOOK.EXE, Version: 14.0.7165.5000
- Error Code: "Add-in execution error. Outlook crashed during the 'SelectionChange' callback of the 'ExplorerEvents_10' interface while calling into the 'xxxxx_class' add-in." (xxxxx is my add-in)
The code I use is the following, where MItem is a global variable:
MItem: Outlook2000.TMailItem;
procedure TAddInModule.ConnectToFolder();
begin
if not Assigned(FFolderEvents) then begin
FFolderEvents := TMAPIFolderEvents.Create(nil);
FFolderEvents.OnBeforeFolderMove := DoBeforeFolderMove;
FFolderEvents.OnBeforeItemMove := DoBeforeItemMove;
end;
FFolderEvents.ConnectTo(OutlookApp.ActiveExplorer().CurrentFolder);
end;
procedure TAddInModule.DoBeforeFolderMove(ASender: TObject;
const MoveTo: MAPIFolder; var Cancel: WordBool);
begin
if Assigned(MItem) then MItem.Disconnect();
Cancel := False;
// ShowMessage('Before Folder Move!');
end;
procedure TAddInModule.DoBeforeItemMove(ASender: TObject;
const Item: IDispatch; const MoveTo: MAPIFolder; var Cancel: WordBool);
begin
if Assigned(MItem) then MItem.Disconnect();
Cancel := False;
// ShowMessage('Before Item Move!');
end;
procedure TAddInModule.adxOutlookAppEvents1ExplorerSelectionChange(Sender: TObject);
var
sel : Selection;
item: _MailItem;
begin
try
sel := OutlookApp.ActiveExplorer.Selection;
except
end;
if Assigned(sel) and (sel.Count = 1) then begin
sel.Item(1).QueryInterface(IID__MailItem, item);
if Assigned(item) then begin
// showMessage('Selection Change');
if Assigned(MItem) then MItem.Disconnect();
MItem := TMailItem.Create(self);
readXHeaderInfo := GetXHeader(item.MAPIOBJECT as IMessage, myXHeaderName); // this calls a procedure to read X-Header inforamtion from the selected MailItem
MItem.OnReply := DoOnReply;
MItem.OnReplyAll := DoOnReplyAll;
MItem.OnForward := DoOnForward;
MItem.ConnectTo(item);
ConnectToFolder(); // required to disconnect from MItem when item is moved
item := nil;
end;
end;
sel := nil;
end; |
|
Andrei Smolin
Add-in Express team
Posts: 18825
Joined: 2006-05-11
|
|
Ralf Garbe
Posts: 20
Joined: 2014-11-22
|
Hello Andrei,
Great I will have a study on the debug method shown.
Unfortunatelly I will not be able to do that with my customer.
I assume it is important to know during which command the application fails - I will find a solution where the output will be written to a file.
I will let you know then.
Any other idea how and when such behaviour occurs? Or is there better code to achieve the above?
Thanks for your help,
Ralf |
|
Andrei Smolin
Add-in Express team
Posts: 18825
Joined: 2006-05-11
|
Hello Ralf,
I have no suggestions. The code looks correct to me.
Andrei Smolin
Add-in Express Team Leader |
|
Ralf Garbe
Posts: 20
Joined: 2014-11-22
|
Hello Andrei,
thanks for your support.
Looks like the problem is in the function to read X-Header information from the Email:
readXHeaderInfo := GetXHeader(item.MAPIOBJECT as IMessage, myXHeaderName);
I will further debug that function and might open an new Topic if necessary.
Thanks again,
Ralf |
|
Andrei Smolin
Add-in Express team
Posts: 18825
Joined: 2006-05-11
|
Hello Ralph,
No problem.
Andrei Smolin
Add-in Express Team Leader |
|