Posts 1 - 10 of 19
First | Prev. | 1 2 | Next | Last
|
|
Andrei Bazhgin
Posts: 89
Joined: 2009-09-30
|
I'm searching for sample code/example of how to add a custom column to the Outlook mail view. I'm using Add-in Express 2009 for VCL. I am using Outlook 2003. Installer name was: adxvcl-v501-b0504-std.exe
For example, I want to add a column named "Is Archived" next to the "Subject" column, how do I do this?
Thanks |
|
Posted 30 Sep, 2009 17:05:52
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18843
Joined: 2006-05-11
|
Hello tezka,
Basically, Outlook allows the user to add predefined columns to the view. To do this programmatically, you need to modify the View.XML property. As to custom columns, you need to add a UserProperty to an item using item.UserProperties.Add; one of the parameters provided by this method specifies if the UserProperty will be added to the folder columns list. Please see http://outlookcode.com/threads.aspx?forumid=5&messageid=9161.
Andrei Smolin
Add-in Express Team Leader |
|
Posted 01 Oct, 2009 05:36:06
|
|
Top
|
|
Andrei Bazhgin
Posts: 89
Joined: 2009-09-30
|
Okay, I was able to add the column to the current view by executing the following code:
XMLDocument1.LoadFromXML(OutlookApp.ActiveExplorer.CurrentView.XML);
newNode := XMLDocument1.ChildNodes.Last.AddChild('column');
newNode.AddChild('heading').Text := 'Is Archived';
newNode.AddChild('type').Text := 'boolean';
newNode.AddChild('width').Text := '100';
newNode.AddChild('prop').Text := 'http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/Is%20Archived';
newNode.AddChild('style').Text := 'text-align:left;padding-left:3px';
XMLDocument1.SaveToXML(xmlString);
OutlookApp.ActiveExplorer.CurrentView.XML := xmlString;
OutlookApp.ActiveExplorer.CurrentView.Apply;
Now, how do I assign values to every cell in this column based on information from the email message?
How do I assign a property to an email message so that its value will always show up in this column (yes/no value) |
|
Posted 01 Oct, 2009 16:10:47
|
|
Top
|
|
Andrei Bazhgin
Posts: 89
Joined: 2009-09-30
|
I was able to add a column and assign it to individual mail items using the code below, however I am not sure what some of the code means as the Outlook documentation is kind of small.
mail := OutlookApp.ActiveExplorer.Selection.Item(1);
mail.UserProperties.Add('Is Archived', olText, True, 1).Value := 'yes'; |
|
Posted 01 Oct, 2009 16:57:28
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18843
Joined: 2006-05-11
|
|
Posted 02 Oct, 2009 06:25:47
|
|
Top
|
|
Andrei Bazhgin
Posts: 89
Joined: 2009-09-30
|
My only problem now is that I can not use the "olYesNo" column type. The following code should add a column that's Yes/No and set the value to Yes, but it doesn't do anything to the column cell.
mailObj.UserProperties.Add('Is Archived', olYesNo, True, 1).Value := True;
mailObj.Save;
I've tried to use different values like True, 'True', 'Yes', but nothing works. |
|
Posted 02 Oct, 2009 16:43:22
|
|
Top
|
|
Andrei Bazhgin
Posts: 89
Joined: 2009-09-30
|
Doesn't Delphi release COM pointers automatically for you?
What function do I use in Delphi to release a com object. I've tried Marshal.ReleaseComObject() but I cant find where it is declared.
Right now I am just doing this:
IExpl := OutlookApp.ActiveExplorer();
ISelection := IExpl.Selection;
ISelection._Release;
Is this the right way to do it? |
|
Posted 02 Oct, 2009 18:13:49
|
|
Top
|
|
Andrei B
Posts: 89
Joined: 2009-09-30
|
|
Posted 02 Oct, 2009 23:58:31
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18843
Joined: 2006-05-11
|
Hello Andrei,
Doesn't Delphi release COM pointers automatically for you?
Ooops, that's my fault; I've missed the fact that you're using Delphi. Please disregard my comment on releasing COM objects. It's an important thing, of course but I do know that Delphi developers know about this far better than .NET developers.
I've just tested creating a UserProperty. The code below works fine for me: Outlook 2007 automatically refreshes the value of the UserProperty, which is displayed in the corresponding column.
mail := MailItem(OutlookApp.ActiveExplorer().Selection.Item(1));
up := mail.UserProperties.Item('Is Archived');
if (up = nil) then up := mail.UserProperties.Add('Is Archived', olYesNo, True, 1);
up.Value := True;
mail.Save;
Is this what you were talking about?
Andrei Smolin
Add-in Express Team Leader |
|
Posted 03 Oct, 2009 05:42:09
|
|
Top
|
|
Andrei B
Posts: 89
Joined: 2009-09-30
|
Andrei,
when I try to compile this code with Delphi 2009 I get an error:
var
mail : MailItem;
up : UserProperty;
...
mail := MailItem(mailObj); // mailObj is OleVariant
up := mail.UserProperties.Item('Is Archived'); // *** THIS IS WHERE ERROR LINE IS ***
if (up = nil) then up := mail.UserProperties.Add('Is Archived', olYesNo, True, 1);
up.Value := True;
mail.Save;
Error I get is: [DCC Error] FormMain.pas(199): E2089 Invalid typecast
Why am I getting this error?
Updated: correct line where error shows up |
|
Posted 05 Oct, 2009 15:16:18
|
|
Top
|
|
Posts 1 - 10 of 19
First | Prev. | 1 2 | Next | Last
|