2011-10-24 51 views

回答

2

声明:这肯定可以通过COM,但Outlook将显示警告,第三方应用程序正在访问地址簿(以及正确的)。如果要避免这些警告,可以从Outlook加载项中运行代码,然后使用MAPI,或使用Outlook Redemption,这基本上是一种围绕MAPI的高级包装,它与Outlook对象模型类似。

Outlook对象模型提供了SelectNamesDialog对话框来显示地址簿。它具有高度可配置性,您也可以使用自定义地址集来初始化它。

作为一个小例子,下面是一些在多选模式下弹出地址簿的代码。为简洁起见,它使用后期绑定(OleVariants)。您可能会希望在生产代码中使用早期绑定。

procedure TForm1.Button1Click(Sender: TObject); 
var 
    application: OleVariant; 
    dialog: OleVariant; 
    i: Integer; 
    recipients: String; 
    recipient: OleVariant; 

begin 
    application := createOleObject('Outlook.Application'); 

    // Obtain the dialog 
    dialog := application.session.getSelectNamesDialog; 

    // Only show the a single 'add' field, multiselect 
    dialog.setDefaultDisplayMode(6); // 6 = olDefaultDelegates 

    // Display the dialog 
    dialog.display; 

    // Display selection 
    recipients := ''; 
    for i := 1 to dialog.recipients.count do 
    begin 
     recipient := dialog.recipients.item(i); 

     recipients := recipients + recipient.name + #13#10; 
    end; 

    showMessage(recipients); 
end; 
+0

感谢您的详细信息 - 不清楚MAPI是否与Outlook对象模型不同 - 不适合Office/Exchange集成等。 – Vector

2

为了做这样的事情,你需要支持扩展MAPI接口。

这里是一个组件的链接,它在Win7-64 Outlook-2010上支持此功能。

Easy MAPI

支持地址簿对话的执行。

+0

+1 - 我可能会最终使用Easy MAPI,但我指出了其他答案,因为@ Paul-Jan解释了不同的选项等。谢谢。 – Vector