Outlook Categories Issue

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

Outlook Categories Issue
 
Greg Saunders




Posts: 11
Joined: 2012-07-19
In our Delphi 6 version of our application and older Add-In Express tied to Outlook 2003 - 2007 we once used the following code to set the Flag Color

procedure TAddInModule.ItemsAdd(ASender: TObject; var Item: IDispatch); 
var 
  UserProp1: UserProperty; 
  iMail: _MailItem; 
  FileName: String; 
 
begin 
  iMail := Item as _MailItem; 

  iMail.FlagIcon := 1 ;    //purple flag 
  iMail.FlagStatus := olFlagMarked;
  iMail.FlagRequest := 'Filed In Vault' ; 
  iMail.ReminderSet := False ; 
  iMail.Save ; 
  iMail.SaveAs(FileName); 
  SetComplete(UserProp1.Value); 
end; 


The key code is the iMail.FlagIcon := 1 which set the flag to purple.

We are now in the world for us of Outlook 2010 through 2016 and will be all 2016 in near future and using newest Add-In Express and Delphi XE5.

Since the flag colors were removed in Outlook 2010 the next option is using Categories. So we want to do the following:

- On Outlook start check the master category list and see if "Vaulted" exists already and if it does make sure it is purple.
- If it does not exist then create the category and set the color to purple.
- Now when our Add-In does what it is supposed to do with a mail item we will then set the category of the mail item to the "Vaulted"

Looking at all the examples it seems I should be looking at namespace to get access to the categories.

So I tried:


var
  MAPINameSpace : _NameSpace
  Categories : Widestring;

begin
  MAPINameSpace := OutlookApp.GetNameSpace('MAPI');

  Categories := MAPINameSpace.Categories;
end;


I am finding Categories is NOT available above and compiles as "undeclared identifier".

Everything points to categories being available via NameSpace, but that doesn't seem to be the case.

I would appreciated any wisdom you could share.

Greg
Posted 26 Jan, 2017 11:03:02 Top
Greg Saunders




Posts: 11
Joined: 2012-07-19
Ok... after using Google to help search this site (was having difficult time finding anything with the forum search) I found the following:


Because the Categories object and NameSpace.Categories property were introduced in Outlook 2007 and Add-in Express provides objects from the Outlook 2000 type library, you can use late binding or access that property directly by importing the type library of Outlook 2007, 2010, 2013 or 2016. See also Using Outlook2010 instead of Outlook2000.


I am not quite sure exactly what I should be doing. Here is what I think I am doing:

- My project is open.
- I go to View / Registered Type Libraries.
- Find Microsoft Office 16.0 Object Library and Import it.
- Find Microsoft Outlook 16.0 Object Library and Import it.
- Add Library Path to the folder the Type Libraries were imported into.
- In my application I then put the Outlook_TLB unit in the uses clause BEFORE the Outlook2000 unit. (If I didn't put it before it led to some compiler errors)

- Then could use the following to get to the categories.


procedure TAddInModule.adxCOMAddInModuleAddInStartupComplete(Sender: TObject);
var
  ol2010 : Outlook_Tlb._Application;
  Categories : _Categories;
  Category   : _Category;
  i : integer;

begin
  ol2010 := OutlookApp.Application as Outlook_Tlb._Application;
  categories := ol2010.Session.Categories;
  ShowMessage('Category Count: ' + IntToStr(Categories.Count));
  for i := 1 to Categories.Count do
  begin
    Category := Categories.Item(i);
    ShowMessage('Category Name: ' + Category.Name + '  |  Category Color: ' + IntToStr(Category.Color))
  end;


I don't know if I did everything correctly, but it seems to work.

Question... for those that know all of their Office products are 2010 or higher does anyone just replace all units Add-In Express units containing Outlook2000 in the uses clause with Outlook2010? If so would anything else need to be done like also importing the type library?

Thanks,

Greg
Posted 26 Jan, 2017 16:02:34 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Greg,

You can't just replace Outlook2000 with Outlook2010 as Add-in Express exposes objects from the Office 2000 type libraries. When using such objects, you may need to cast an object returned by Add-in Express to the type provided by the corresponding type library.


Andrei Smolin
Add-in Express Team Leader
Posted 27 Jan, 2017 04:13:02 Top
Greg Saunders




Posts: 11
Joined: 2012-07-19
Andrei,

In my previous reply I gave example of what I did and steps I followed... does that all look correct to you?

Greg
Posted 30 Jan, 2017 13:57:51 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Greg,

I just import the type library (it's Outlook 2013 in my case). Doing this adds the imported unit *after* Outlook2000:

uses
  ..., Office2000, ..., Outlook2000, ... Outlook2013_TLB;


Reverting the order of units may produce compile-time errors.

Your code works for me:

procedure TAddInModule.adxRibbonTab1Controls3Controls0Click(
  Sender: TObject; const RibbonControl: IRibbonControl);
var
  ol2013 : Outlook2013_Tlb._Application;
  Categories : _Categories;
  Category   : _Category;
  i : integer;

begin
  ol2013 := OutlookApp.Application as Outlook2013_Tlb._Application;
  categories := ol2013.Session.Categories;
  ShowMessage('Category Count: ' + IntToStr(Categories.Count));
  for i := 1 to Categories.Count do
  begin
    Category := Categories.Item(i);
    ShowMessage('Category Name: ' + Category.Name + '  |  Category Color: ' + IntToStr(Category.Color))
  end;
end;



Andrei Smolin
Add-in Express Team Leader
Posted 31 Jan, 2017 03:24:41 Top