|
Gürcan YÜCEL
Guest
|
Hi,
Im developing MS Outlook Addin with D7 ent+Addin Express V2.2 on W2K. First I design and run code in Outlook 2000. Everytgins work fine. I try to test in Outlook 2003. My save line raises exceptin. How can I save eMail in 2003? And how can I write the code that run both? ({$IFDEF})
Here is my 2000 code;
var
TmpMailItem:MailItem;
....
//exception on this line
TmpMailItem:=_MailItem(OutlookApp.ActiveExplorer.Selection.Item(i));
//this lines work well in 2000
EMailName:='c:\Test.msg';
TmpMailItem.SaveAs(EMailName,olMSG);
Thanks
Gürcan YÜCEL
|
|
Posted 01 Oct, 2004 09:21:00
|
|
Top
|
|
Dmitry Kostochko
Add-in Express team
Posts: 2880
Joined: 2004-04-05
|
There could be several causes of the exception:
- Outlook doesn't have ActiveExplorer.
- Selection doesn't contain Item(i).
- Selection contains Item(i) but it isn't _MailItem.
Please give more details of your exception.
Sincerely,
ADX Support Team |
|
Posted 01 Oct, 2004 09:32:57
|
|
Top
|
|
Gürcan YÜCEL
Guest
|
Hi Dmitry,
Thanks for the answer.
OutlookApp.ActiveExplorer.Selection.Count returns 1. I thing there is another problem here. I debug the code. And add line ;
if OutlookApp.ActiveExplorer.Selection.Item(1)=nil then ShowMessage('excep');
there is no message.
next line is;
TmpMailItem:=_MailItem(OutlookApp.ActiveExplorer.Selection.Item(1));
and Im getting exception here. I thing the problem is casting. Any idea?
Gürcan YÜCEL
|
|
Posted 01 Oct, 2004 10:13:40
|
|
Top
|
|
Gürcan YÜCEL
Guest
|
Ok,
I found the exact problem line;
when I cast as TmpMailItem line, there is no exception. Exception raises when I try to use TmpMailItem. For example;
TmpMailItem.SenderName (infact its widestring), TmpMailItem.HTMLBody or any property of _MailItem.
Now, I believe that there is a problem casting. Any idea?
Gürcan YÜCEL |
|
Posted 01 Oct, 2004 10:29:44
|
|
Top
|
|
Dmitry Kostochko
Add-in Express team
Posts: 2880
Joined: 2004-04-05
|
var
IDsp: IDispatch;
MItem: _MailItem;
begin
IDsp := nil;
if (OutlookApp.ActiveExplorer <> nil) and
(OutlookApp.ActiveExplorer.Selection.Count > 0) then
IDsp := OutlookApp.ActiveExplorer.Selection.Item(1);
if Assigned(IDsp) then
try
IDsp.QueryInterface(IID__MailItem, MItem);
if Assigned(MItem) then
try
MItem.SaveAs(...);
finally
MItem := nil;
end;
finally
IDsp := nil;
end;
end;
Done?
Sincerely,
ADX Support Team |
|
Posted 01 Oct, 2004 10:32:26
|
|
Top
|
|
Gürcan YÜCEL
Guest
|
Hi Dmitry,
I change my code to yours. Now Its working.:) Thanks for the help. I want to write some notes for future use;
1.There can be more than 1 selected item. For this reason you had to iterate them.(OutlookApp.ActiveExplorer.Selection.Count)
2.If you want only email (not read receipt etc.) you had to test every time its a email or not.
Thanks again.
Gürcan YÜCEL |
|
Posted 04 Oct, 2004 02:50:04
|
|
Top
|
|
Dmitry Kostochko
Add-in Express team
Posts: 2880
Joined: 2004-04-05
|
Hello Gürcan,
I am glad the code works. Your comments are absolutely right. Good luck.
Sincerely,
ADX Support Team |
|
Posted 04 Oct, 2004 05:26:56
|
|
Top
|
|