dexterb
Posts: 19
Joined: 2007-04-16
|
I need to support Outlook 2003 -> 2010. If the Outlook version is >= 2007, I would like to be able to create Rules programmatically. What alternatives do I have? I have read somewhere in the forum regarding the use of Office PIAs - are there examples that show how to use the Office PIAs?
Currently using Delphi 5 Ent.;
-
dexterb |
|
Dmitry Kostochko
Add-in Express team
Posts: 2875
Joined: 2004-04-05
|
Hi Dexterb,
Add-in Express for Office and VCL supports the Office 2000 Object Model and creates COM add-in projects using the default Delphi class wrappers located in Office2000.pas, Outlook2000.pas, Excel2000.pas and other corresponding source units.
To support a particular host application version (Outlook 2003 in your case) you can use two approaches:
1. Use late binding. In this case you can get access to all new objects/properties/methods of the Outlook 2003 Object Model by using the OLEVariant type. Please see the sample code below:
procedure TAddInModule.adxCOMAddInModuleAddInInitialize(Sender: TObject);
var
ns: _Namespace;
isOffline: boolean;
begin
// Outlook 2003
if Self.HostMajorVersion >= 11 then begin
ns := OutlookApp.GetNamespace('MAPI');
if Assigned(ns) then
try
[B]isOffline := OLEVariant(ns).Offline;[/B]
if isOffline then
ShowMessage('Outlook is Offline now!')
else
ShowMessage('Outlook is Online now!')
finally
ns := nil;
end;
end;
end;
2. Use early binding. Go to Project -> Import Type Library, search and select the "Microsoft Outlook 11.0 Object Library" type library (you need to have Office 2003 installed on your development machine) and click the Create Unit button. Delphi will import the type library and create a new class wrapper source file. You can use it in your project directly, please see the sample code below:
[B]uses Dialogs, Outlook_TLB;[/B]
procedure TAddInModule.adxCOMAddInModuleAddInInitialize(Sender: TObject);
var
[B]ns: Outlook_TLB._Namespace;[/B]
isOffline: boolean;
begin
// Outlook 2003
if Self.HostMajorVersion >= 11 then begin
[B]ns := OutlookApp.GetNamespace('MAPI') as Outlook_TLB._Namespace;[/B]
if Assigned(ns) then
try
isOffline := ns.Offline;
if isOffline then
ShowMessage('Outlook is Offline now!')
else
ShowMessage('Outlook is Online now!')
finally
ns := nil;
end;
end;
end;
|
|
dexterb
Posts: 19
Joined: 2007-04-16
|
Dmitry,
Thank you for your help.
I actually have a c# project (vsto) and I am simply trying to convert it to delphi.
C#----
colRules.Create(RuleName, Outlook.OlRuleType.olRuleReceive);
Delphi----
vApp:=CreateOleObject('Outlook.Application');
rRules:=vApp.Session.DefaultStore.GetRules;
....more code here....
rRules.Create(RuleName, Outlook.olRuleType.olRuleReceive);
How do I force it to see that Outlook.olruletype enum which only exist in Outlook 2007?
thanks.
-
dexterb |
|
dexterb
Posts: 19
Joined: 2007-04-16
|
Dmitry,
Your first suggested method works but then I lose all the "intellisense" capabilities in Delphi.
As a side question, what if I want to only support Outlook 2007 and up, is there a way that I can make the project only work with Outlook 2007 and provide me direct access to the new features in Outlook 2007 natively (no casting to olevariant)?
Thanks.
-
dexterb |
|
Dmitry Kostochko
Add-in Express team
Posts: 2875
Joined: 2004-04-05
|
Hi dexterb,
Thank you for the details.
Please try to use #2 approach described in my previous post. I.e. import the Outlook 2007 type library and use the imported interfaces in your add-in code directly. |
|