Problem with HOWTO re: Outlook's SelectionChange event

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

Problem with HOWTO re: Outlook's SelectionChange event
Marcela Haendler

Posts: 1
Joined: 2005-07-15
I downloaded the HOWTO for handling Outlook's SelectionChange event, but it won't compile on my machine. I have Delphi version 6, with all Borland's patches.

The problem is with the DoNewExplorer and DoNewInspector event handlers. These are their definitions:

TAddInModule = class(TadxCOMAddInModule)
procedure DoNewExplorer(ASender: TObject; const Explorer: _Explorer);
procedure DoNewInspector(ASender: TObject; const Inspector: _Inspector);

In the procedure TAddInModule.adxCOMAddInModuleAddInInitialize(Sender: TObject), these event handlers appear in two assignment statements:

FExplorers.OnNewExplorer := DoNewExplorer;
FInspectors.OnNewInspector := DoNewInspector;

There is an 'Incompatible types' error for these assignments: 'Parameter lists differ'. For instance, the type of FExplorers.OnNewExplorer is TExplorersNewExplorer, which is of the following type:

procedure(Sender: TObject, var Explorer: OleVariant) of object.

The problem is the same with FInspectors.OnNewInspector's type of TInspectorsNewInspector: the second parameter in the procedure type is an OleVariant, not an _Inspector.

I tried changing the parameter lists for DoNewExplorer and DoNewInspector, then typecasting their second parameters to OleVariant whenever they're called. That works, but creates problems inside the event handlers. For instance, see the following code with the changed parameter list:

procedure TAddInModule.DoNewExplorer(ASender: TObject;
var Explorer: OleVariant);
Expl: TExplorer;
Expl := TExplorer.Create(nil);
Expl.OnSelectionChange := DoSelectionChange;
Expl.OnClose := DoCloseExplorer;

The Exp1.ConnectTo(Explorer) line no longer works, now that I've changed the type of the Explorer parameter to OleVariant. When I try to typecast it back to an _Explorer, it still doesn't work:

Expl.ConnectTo( _Explorer(Explorer) );

This produces the following compile error:

[Error] OL_SelectionChange_IMPL.pas(82): Incompatible types: 'OleVariant' and '_Explorer'

Any ideas how I can get this HOWTO running?

Thank you very much for any help.

Best regards,
Posted 15 Jul, 2005 11:11:38 Top
Dmitry Kostochko

Add-in Express team

Posts: 2880
Joined: 2004-04-05
Hi Marcela,

Try the code below:
Expl.ConnectTo(IDispatch(Explorer) as _Explorer);
Posted 15 Jul, 2005 11:34:08 Top