Wolfgang Denz
Posts: 18
Joined: 2011-08-05
|
Hi,
I have developed a plugin for Word, Excel and Outlook with Add-In-Exporess for VCL.
The plugin works fine except for the combination with Outlook 2003. Below is a snippet of the Code.
Accessing Mailitem.Subject causes an exception in Outlook2003. Outlook 2007 works fine.
Can you give me a hint what I'm doing wrong?
Thanks in advance
Wolfgang
try
Logout('Outlook Start');
IExplorer := OutlookApp.ActiveExplorer;
Logout('Outlook Explorer init');
except
end;
if Assigned(IExplorer) then
begin
try
Logout('Outlook Assigned');
Mailitem := GetMailItem(IExplorer);
Logout('Outlook Mailitem get');
IndizierForm := TIndizierform.Create(self);
Indizierform.mZusatzinfo.Clear;
Logout('Outlook Indizierform created');
Indizierform.mZusatzinfo.Lines.add('Betreff: '+Mailitem.Subject); //-> access violation with Outlook 2003
The function GetMailItem which is used in the code is attached below
function GetMailItem(const ExplorerOrInspector: IDispatch): _Mailitem;
var
IExplorer: _Explorer;
ISelection: Selection;
IInspector: _Inspector;
begin
if (ExplorerOrInspector <> nil) then
begin
ExplorerOrInspector.QueryInterface(IID__Inspector, IInspector);
if Assigned(IInspector) then
try
Result := _Mailitem(IInspector.CurrentItem);
finally
IInspector := nil;
end
else
begin
ExplorerOrInspector.QueryInterface(IID__Explorer, IExplorer);
if Assigned(IExplorer) then
try
try
ISelection := IExplorer.Selection;
except
ISelection := nil;
end;
if Assigned(ISelection) then
try
if ISelection.Count > 0 then
Result := _Mailitem(ISelection.Item(1));
finally
ISelection := nil;
end;
finally
IExplorer := nil;
end;
end;
end;
end;
|
|
Dmitry Kostochko
Add-in Express team
Posts: 2875
Joined: 2004-04-05
|
Hi Wolfgang,
Thank you for the code sample. I can assume that you have some item other than mail selected in the Outlook 2003 explorer window. I would suggest using the ISelection.Item(1).QueryInterface(IID__MailItem, Result) code instead of direct casting. |
|
Wolfgang Denz
Posts: 18
Joined: 2011-08-05
|
Thanks Dmitry,
it's working now
Regards
Wolfgang |
|