TadxOutlookAppEvents OnInspectorActivate problem.

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

TadxOutlookAppEvents OnInspectorActivate problem.
Cannot get the current Inspector. 
Subscribe
Dave O'Brien




Posts: 51
Joined: 2019-09-02
I am attempting to check if the current Inspector email item has attachments and enable/disable a button. I have added the showmessage to see what the subject is. It always shows the first Inspector Item opened if there are multiple open, not the current one.

I have seen a post that OnInspectorActivate provides the Inspector object, but I don't see that here. How do I get the current Inspector?

The following code appears to always return the first Inspector, not the current inspector.

procedure TIDMAddInModule.adxOutlookAppEvents1InspectorActivate(Sender: TObject);
var
   Item: MailItem;
begin

   // When an inspector form is activated
   SetRibbonControlStatus('rbInspSendAttachmentsToIDM', False);
   try
      Item := OutlookApp.ActiveInspector.CurrentItem as MailItem;
      // SetRibbonControlStatus('rbInspSendAttachmentsToIDM', GetAttachmentStatus(Item));
      ShowMessage(Item.Subject);
   except
      on e: Exception do
      begin

         // No need to show error
      end;
   end;
end;
Posted 14 Oct, 2024 00:48:47 Top
Andrei Smolin


Add-in Express team


Posts: 19095
Joined: 2006-05-11
Hello Dave,

Add-in Express passes an Outlook2000.TInspector to this event procedure. That's the inspector being activated.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 14 Oct, 2024 08:37:40 Top
Dave O'Brien




Posts: 51
Joined: 2019-09-02
Thanks. I was trying to cast Sender as _Inspector, didn't think of TInspector...
Posted 14 Oct, 2024 19:47:31 Top
Dave O'Brien




Posts: 51
Joined: 2019-09-02
Unfortunately, my attempt to get this working has failed with "Invalid typecast":

Inspector: TInspector; ?? What is this?

Sender as TInspector --> Invalid Typecast.

Outlook2000 has TInspectors, but no TInspector.

What am I missing here?
Posted 14 Oct, 2024 20:18:36 Top
Dave O'Brien




Posts: 51
Joined: 2019-09-02
Any code examples I could use for InspectorActivate?
Posted 16 Oct, 2024 03:24:10 Top
Andrei Smolin


Add-in Express team


Posts: 19095
Joined: 2006-05-11
Hello Dave,

You are right and I was wrong. Below is what works for me:

procedure TAddInModule.adxCOMAddInModuleOLInspectorActivate(Sender: TObject);
var
insp : Inspector;
begin
if Assigned(Sender) then
begin
  OutputDebugString(PWideChar('!!! ' + TInspector(Sender).Caption));
end;
end;


Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 16 Oct, 2024 13:20:18 Top
Dave O'Brien




Posts: 51
Joined: 2019-09-02
OnNewInspector gives me what I need, didn't see that event previously.
NewInspector(ASender: TObject; const Inspector: _Inspector).

Why doesn't InspectorActivate also pass the Inspector? I can't see any way to tell which Inspector it is.
InspectorActivate(ASender: TObject)
Posted 16 Oct, 2024 22:36:03 Top
Dave O'Brien




Posts: 51
Joined: 2019-09-02
After much testing, the issue remains that if I have 2 inspectors open, the button I want disabled if there are no attachments, follows the last Inspector to open, not the current Inspector window, so I still need to be able to work out which Inspector is selected, therefore need the InspectorActivate event to work out the current Inspector and enable/disable the button.
Posted 16 Oct, 2024 22:52:27 Top
Dave O'Brien




Posts: 51
Joined: 2019-09-02
Got around the issue in OnInspectorActivate by firing a 10ms timer so that ActiveInspector is the correct Inspector window.

OnInspectorActivate should be called OnBeforeInspectorActivate, because ActiveInspector at this stage is the Inspector you were on before, not the one you are activating.

The timer sorts this out by allowing the Window change to complete before processing.
Posted 17 Oct, 2024 01:34:52 Top
Andrei Smolin


Add-in Express team


Posts: 19095
Joined: 2006-05-11
Hello Dave

Dave O'Brien writes:
I can't see any way to tell which Inspector it is.


You didn't notice my code sample?

Dave O'Brien writes:
Why doesn't InspectorActivate also pass the Inspector?


I guess this was a design decision. Obviously, not a good one.

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 18 Oct, 2024 12:07:00 Top