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.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.
Add-in Express team
Try the code below:
Expl.ConnectTo(IDispatch(Explorer) as _Explorer);