Outlook getSelectNamesDialog

Giganews Newsgroups
Subject: Outlook getSelectNamesDialog
Posted by:  Martin Zinaich
Date: Mon, 22 Jul 2013

I have very limited experience in this area, so sorry if this is a dumb question.  I'm simply trying to open an Outlook Address Book - Select Names Dialog and pull in the phone numbers of the selected contact.  I am able to do it with the code below for the Global Address List (GAL), however if I pick the Contacts folder when the Select Names Dialog is open (my personal address book in Outlook) it throws an exception on return.  Any ideas - I would have thought the same call would work for any contact in
the address book.  Is there a better way to call the Select Names api and pull in the selected user's Phone Numbers be that entry a GAL or Local entry? (I'm using Delphi 2010 or XE4 if that matters)

This works if I pick a GAL entry but not if I pick a local Contact---

Procedure TForm1.GetPhoneNumber;
Var
appl: OleVariant;
dialog: OleVariant;
oContacts: OleVariant;
recipient: OleVariant;
SelItem: OleVariant;
oAEntry: OleVariant;
oEUser: OleVariant;

Begin

Try
    appl := GetActiveOleObject('Outlook.Application');
  Except
    appl := CreateOleObject('Outlook.Application');
  end;

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

  application.Minimize;
  // Only show the a single 'add' field, multiselect
  dialog.setDefaultDisplayMode( 6 ); // 6 = olDefaultDelegates
  dialog.NumberOfRecipientSelectors := 1;
  dialog.ShowOnlyInitialAddressList := false;
  dialog.AllowMultipleSelection := false;

  // Display the dialog
  dialog.display;
  application.Restore;
  form1.SetFocus;
  // Display selection

If dialog.recipients.count <> 0 then
  begin
      recipient := dialog.recipients.item(1);
      oAEntry := recipient.AddressEntry;
      oEUser := oAEntry.GetExchangeUser;
      bnumber := (oEUser.BusinessTelephoneNumber);
      mnumber := (oEUser.MobileTelephoneNumber);
  end
else
  begin
    VarClear(appl);
    exit;
  end;

Replies