Why is OutlookApp.ActiveExplorer.Selection slow?

Add-in Express™ Support Service
That's what is more important than anything else

Why is OutlookApp.ActiveExplorer.Selection slow?
Selecting a large group of items... 
Advatel Company




Posts: 11
Joined: 2006-05-15
Why is it that the OutlookApp.ActiveExplorer.Selection seems to have trouble the more items that are selected?

Thought we could be clever by checking the count for one item but even getting the count is slow.

Is there a quick way to know if there is only one Selected Item on SelectionChange?
Posted 29 May, 2006 21:52:20 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi,

Please show me your code of the OnSelectionChange event handler.

Posted 30 May, 2006 05:33:26 Top
Advatel Company




Posts: 11
Joined: 2006-05-15

procedure TAddInModule.OutlookAppEventsExplorerSelectionChange(
  Sender: TObject);
var
  SelectedMail : MailItem;
  SelectedContact : ContactItem;
  cntNumber : Integer;
  Selection : Outlook2000.Selection;
  LastCursor : TCursor;
  EID: WideString;
begin
  OutputDebugString('Explorer Selection Changed');
  LastCursor := Screen.Cursor;
  Screen.Cursor := crHourGlass;
  CmdBarOE.Controls.Items[0].AsComboBox.Clear;
  EID := OutlookApp.ActiveExplorer.CurrentFolder.EntryID;
  if (EID = OutlookApp.Session.GetDefaultFolder(olFolderOutbox).EntryID)
  or (EID = OutlookApp.Session.GetDefaultFolder(olFolderSentMail).EntryID)
  or (EID = OutlookApp.Session.GetDefaultFolder(olFolderDrafts).EntryID)
  or (EID = OutlookApp.Session.GetDefaultFolder(olFolderDeletedItems).EntryID)
  then
    Selection := nil
  else
    try
      if OutlookApp.ActiveExplorer.Selection.Count = 1 then
        Selection := OutlookApp.ActiveExplorer.Selection
      else
        Selection := nil;
    except
      on EOleException do Selection := nil;
      on EAccessViolation do Selection := nil;
    end;
  if Assigned(Selection) then
  begin
    if (Selection.Item(1).QueryInterface(IID__MailItem, SelectedMail) = S_OK) then
    begin
      cntNumber := setMailControls(CmdBarOE.Controls, SelectedMail);
      OlSecurityManager.DisableOOMWarnings := True;
      if (cntNumber > 0) and (FLastEntryID <> SelectedMail.EntryID) then
      begin
        FLastEntryID := SelectedMail.EntryID;
        OutputDebugString(PChar(string('EntryID: ' + FLastEntryID)));
        parseMailItem(SelectedMail);
      end;
      OlSecurityManager.DisableOOMWarnings := False;
    end
    else if (Selection.Item(1).QueryInterface(IID__ContactItem, SelectedContact) = S_OK) then
    begin
      SetContact(CmdBarOE.Controls, SelectedContact);
    end;
  end
  else
    SetContactControls(CmdBarOE.Controls);
  Screen.Cursor := LastCursor;
  OutputDebugString('/Explorer Selection Changed');
end;

setMailControls, parseMailItem, SetContact and SetContactControls are our code that does the rest of our work and are not causing this problem.
Posted 01 Jun, 2006 20:34:38 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05

Thank you. Everything looks ok and I don't see any ways to speed up your code. I know the Selection collection is slow but I didn't think that anyone would notice this fact.

Posted 02 Jun, 2006 05:47:39 Top
Advatel Company




Posts: 11
Joined: 2006-05-15
My Boss was the one that noticed first just selecting a large group of e-mails.
Is there a quicker way to find out if only one item is selected?
Posted 04 Jun, 2006 19:01:21 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05

Is there a quicker way to find out if only one item is selected?


The only way is:

if OutlookApp.ActiveExplorer.Selection.Count = 1 then begin

end;
Posted 05 Jun, 2006 05:06:43 Top