Board index » delphi » Outlook COM-Addin: Slim solution to handle Item events?

Outlook COM-Addin: Slim solution to handle Item events?


2006-01-02 10:27:17 PM
delphi152
Hi all!
Most of the examples of COM-Addins for Outlook I found so far were
written in VB. I have no practical experience in VB(Visual Basic) myself at all but
from those examples it seems that it is possible to simply write a
function named for instance Item_Reply and boom that function will get
called whenever an item is replied to.
The only aproach of handling the same thing in Delphi I found so far
was to hook into the Explorer.SelectionChange event, then loop through
the items in Explorer.Selection, create a TOleServer-descended wrapper
for each of them and finally assign the appropriate event handlers.
Obviously before filling up that internal list of TOleServer's one also
has to make sure all previous wrappers are released again. Compared to
the VB(Visual Basic) approach this seems like utter overkill and from my tests it
seems this technique is indeed associated with a noticeable performance
hit for large selections. Another downside is that this way you do not
even get at items in the result list of Advanced Find or New Mail
notification windows. So this couldn't really be what's going on behind
the scenes in the VB(Visual Basic) addins, could it?
Put differently:
Is there some way in Delphi to globally register event handlers for
items instead of having to do it explicitly on each and every
individual item in sight? So far I have not been able to find anything
to that effect in the OOM... am I just too dumb?
Cheers,
--
Oliver
 
 

Re:Outlook COM-Addin: Slim solution to handle Item events?

No, there is no way to register events handlers for all items automatically,
that is simply impossible even on the theoretical level.
And VB(Visual Basic) is a lot worse than Delphi in this respect. Did you try to use the
TInterfaceList collection in Delphi to handle multiple COM objects?
Did you try to use Inspectors.NewInspector event instead of Item.Reply?
BTW, you might want to look at the Babelfish sample COM addin source code on
my site (url below).
Dmitry Streblechenko (MVP)
www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
"Oliver Giesen" <XXXX@XXXXX.COM>writes
Quote
Hi all!

Most of the examples of COM-Addins for Outlook I found so far were
written in VB. I have no practical experience in VB(Visual Basic) myself at all but
from those examples it seems that it is possible to simply write a
function named for instance Item_Reply and boom that function will get
called whenever an item is replied to.

The only aproach of handling the same thing in Delphi I found so far
was to hook into the Explorer.SelectionChange event, then loop through
the items in Explorer.Selection, create a TOleServer-descended wrapper
for each of them and finally assign the appropriate event handlers.
Obviously before filling up that internal list of TOleServer's one also
has to make sure all previous wrappers are released again. Compared to
the VB(Visual Basic) approach this seems like utter overkill and from my tests it
seems this technique is indeed associated with a noticeable performance
hit for large selections. Another downside is that this way you do not
even get at items in the result list of Advanced Find or New Mail
notification windows. So this couldn't really be what's going on behind
the scenes in the VB(Visual Basic) addins, could it?

Put differently:
Is there some way in Delphi to globally register event handlers for
items instead of having to do it explicitly on each and every
individual item in sight? So far I have not been able to find anything
to that effect in the OOM... am I just too dumb?

Cheers,

--

Oliver
 

Re:Outlook COM-Addin: Slim solution to handle Item events?

Dmitry Streblechenko writes:
Quote
No, there is no way to register events handlers for all items
automatically, that is simply impossible even on the theoretical
level. And VB(Visual Basic) is a lot worse than Delphi in this respect.
So did I misinterpret the VB(Visual Basic) examples? Do they have to react to
SelectionChange and register the individual items' events as well? Or
were you talking about the performance issues?
Also, would you know if there is a way to register to Reply events of
items that are displayed in non-Explorer windows, such as Advanced Find
or the New Mail Notification window?
Quote
Did you
try to use the TInterfaceList collection in Delphi to handle multiple
COM objects?
No, not in this case. I only used TObjectLists as containers for the
TOleServers so far following your Babelfish example. Will do some tests
with TInterfaceList.
Quote
Did you try to use Inspectors.NewInspector event
instead of Item.Reply?
Yes. Actually, so far I have only ever used NewInspector and
InspectorActivate events and thus did have no need for handling Item
events at all. In this particular case however I need information about
the item that is being replied to and as far as I can tell there is no
other way to get at that except via the Item.Reply event, or is there?
Quote
BTW, you might want to look at the Babelfish
sample COM addin source code on my site (url below).
I know that sample well. It was the very basis for most of my work so
far. Thanks a big fat lot for that again!!! :)
However, it does not cover handling Item.Reply events...
BTW: AFAICT your Babelfish and Paul Quall's sample addin are the only
two instances of publicly available sample code for writing COM addins
in Delphi. Does anybody know of any others?
Cheers,
--
Oliver
 

Re:Outlook COM-Addin: Slim solution to handle Item events?

Dmitry Streblechenko writes:
Quote
Yes. And most examples only handle the first selected item by
declaring a single MailItem variable "WithEvents". This does not take
into account multiple selection or multiple Explorers.
I see. Thanks for clearing that up.
Quote
>Also, would you know if there is a way to register to Reply events
>of items that are displayed in non-Explorer windows, such as
>Advanced Find or the New Mail Notification window?

Nope, not that I know of.
Pity.
Then again, in order to reply to or forward such an item most of the
time I'd have to open it in an inspector first and in that case I
can again get at the Item itself from the New Inspector event... hmm,
...
Quote
You can still use Inspectors.NewInspector and look at the item's
subject. If it is empty, it is a new message; if not, it is a reply
or forward. To figure out the item being replied to/forwarded, use
the ActiveExplorer.Selection collection or
Application.ActiveInspector - the idea is that to be able to forward
a message or reply to it, the user must select it first.
That's an exceptionally good point! ;)
Thanks for all the food for thought!
Cheers,
--
Oliver
 

Re:Outlook COM-Addin: Slim solution to handle Item events?

See below
Dmitry Streblechenko (MVP)
www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
"Oliver Giesen" <XXXX@XXXXX.COM>writes
Quote
Dmitry Streblechenko writes:

>No, there is no way to register events handlers for all items
>automatically, that is simply impossible even on the theoretical
>level. And VB(Visual Basic) is a lot worse than Delphi in this respect.

So did I misinterpret the VB(Visual Basic) examples? Do they have to react to
SelectionChange and register the individual items' events as well? Or
were you talking about the performance issues?
Yes. And most examples only handle the first selected item by declaring a
single MailItem variable "WithEvents". This does not take into account
multiple selection or multiple Explorers.
Quote

Also, would you know if there is a way to register to Reply events of
items that are displayed in non-Explorer windows, such as Advanced Find
or the New Mail Notification window?
Nope, not that I know of.
Quote
>Did you try to use Inspectors.NewInspector event
>instead of Item.Reply?

Yes. Actually, so far I have only ever used NewInspector and
InspectorActivate events and thus did have no need for handling Item
events at all. In this particular case however I need information about
the item that is being replied to and as far as I can tell there is no
other way to get at that except via the Item.Reply event, or is there?
You can still use Inspectors.NewInspector and look at the item's subject. If
it is empty, it is a new message; if not, it is a reply or forward. To
figure out the item being replied to/forwarded, use the
ActiveExplorer.Selection collection or Application.ActiveInspector - the
idea is that to be able to forward a message or reply to it, the user must
select it first.
Quote
>BTW, you might want to look at the Babelfish
>sample COM addin source code on my site (url below).

I know that sample well. It was the very basis for most of my work so
far. Thanks a big fat lot for that again!!! :)
However, it does not cover handling Item.Reply events...

BTW: AFAICT your Babelfish and Paul Quall's sample addin are the only
two instances of publicly available sample code for writing COM addins
in Delphi. Does anybody know of any others?
Not that I know of.