使用以下代码块,您可以选择在Outlook中设置的公用文件夹:
const
olPublicContactsFolder = $00000012; //constant for the public folder
begin
Outlook := CreateOleObject('Outlook.Application');
// Get name space
NameSpace := Outlook.GetNameSpace('MAPI');
// Get root public folder
ContactsRoot := NameSpace.GetDefaultFolder(olPublicContactsFolder); //<-- Error
Contacts:= Contactsroot;
如果Outlook中没有公用文件夹(在Outlook中没有设置公用文件夹,没有Exchange Server),则标记的行会出错 .
The question is how to avoid that error by previously detecting if there is a public folder set or not.
使用 a try...finally/except block didn't work 捕获错误作为异常是由Microsoft API(EOleException)在外部引起的 .
我想不出另一种方法来检测文件夹是否存在,因为导致错误的行对于选择公用文件夹并因此获取它的属性至关重要 .
问候
3 回答
为什么不尝试/除了工作? Delphi很好地捕获了EOleSysError异常 . 并且Delphi RTL引发了异常,而不是Outlook - 所有IDispatch友好的库都返回一个错误代码,在使用IErrorInfo请求描述后,RTL将转换为OLE异常 .
如消息所示,Outlook不知道要使用哪个配置文件 . 您需要先登录到MAPI命名空间,然后才能对其执行任何操作 . 即使没有登录信息(例如,当您连接到未连接到Exchange服务器的本地Outlook实例时),也需要执行此操作 .
此Codeblock可以正常工作 . 我想我还有另一个问题,我已经解决了 . 谢谢你的时间 .
Dmitry Streblechenko对他的答案非常正确,我只是将调试器的EOleException误认为是外部的 . 在没有调试器的情况下运行代码不会导致异常,因为它确实被try / exception块捕获 .
在Outlook中使用多个帐户时,Marjan Venemas的答案可能会派上用场 .