Get reference to another "companion" ADXOlForm

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

Get reference to another "companion" ADXOlForm
 
S?bastien Lange




Posts: 34
Joined: 2022-09-21
Hi,

I have created two ADXOlForms. They are displayed in the same conditions (same ExplorerItemTypes and InspectorItemTypes, set for emails mainly).
As for now, they both listen to ADXSelectionChange to detect Explorer selection changes, and Activated to detect Inspector current item changes. First question: is Activated the best event to listen to Inspector.CurrentItem changes ? Maybe ADXInspectorActivate is better?

As these two forms listen to the same event, they execute the same code to detect the "current item", whether it's an email in read mode, compose, reply, etc... It's not optimal and I would like to execute it only once.

My idea is to listen to Selection/CurrentItem changes in the first form only, then inform the second form of the results.

To achieve this, in my First ADXOlForm, I execute this:

var secondFormItem = Globals.ThisAddIn.FormsManager.Items.Cast<ADXOlFormsCollectionItem>().FirstOrDefault(item => item.FormClassName == typeof(SecondForm).FullName);
var secondForm = secondFormItem?.GetForm(InspectorObj ?? ExplorerObj) as SecondForm;
this.SetSecondForm(secondForm);


Is this correct and the best way to get the reference to the second ("companion") ADXOlForm?

The code above should be executed only once, after instances have been created, but before ADXSelectionChange, Activated, or ADXfolderSwitch are raised. What's the best moment to execute this code? In Load event or ADXBeforeFormShow, or another?

Thanks beforehand.

Best regards,
S?bastien
Posted 17 Oct, 2022 02:26:33 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello S?bastien,

Consider handling that event using the ADXOutlookAppEvents component: you need to put it onto the add-in module.

S?bastien Lange writes:
In Load event or ADXBeforeFormShow


ADXOlForm.Load occurs once per life time of an ADXOlForm instance.

ADXOlForm.ADXBeforeFormShow occurs every time the Forms Manager has to show a given ADXOlForm instance. This includes scenarios when the instance becomes hidden/show as a reaction to Outlook windowing: when Outlook hides/shows the target window, the Forms Manager hides and shows the form and the ADXBeforeFormShow event occurs before the ADXOlForm instance becomes shown.

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 17 Oct, 2022 06:10:52 Top
S?bastien Lange




Posts: 34
Joined: 2022-09-21
Hello Andrei,

Whether is is in Load or ADXBeforeFormShow, the code above works only when both instances of ADXOlForms are created. It's not the case in the Load event of the first instance: the second is not instanciated yet.

Can I rely on the assumption that instances of ADXOlForms are always created in the same order as their ADXOlFormsCollectionItem are added to FormsManager.Items?

If true, I can then execute my code in ADXOlForm.Load of the second ADXOlForm.

Best Regards,
S?bastien
Posted 18 Oct, 2022 04:45:04 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello S?bastien,

S?bastien Lange writes:
Can I rely on the assumption that instances of ADXOlForms are always created in the same order as their ADXOlFormsCollectionItem are added to FormsManager.Items?


No, you cannot. Form instances are created as a reaction to Outlook windowing: if Outlook shows the second window first, the second ADXOlFormsCollectionItem will cause the creation of its form earlier than the first ADXOlFormsCollectionItem.

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 18 Oct, 2022 05:32:07 Top