- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm working on an implementation of a modeless form that raises an external event in response to UI inputs from the user. In concept, this is extremely similar to the SDK code example "ModelessForm_ExternalEvent". I've been studying, testing, and debugging that example, and now feel like I understand 99% of what it's doing. It's the final 1% that has me totally stumped.
As I understand it, the class for the RequestHandler contains a public property "Request" that tells the Execute() method which form control was clicked by the user. As a result, the behavior of the Execute() method can be modified from outside the handler by setting the value of the RequestHandler.Request property. This all makes perfect sense.
What I do not understand is how the ExternalEvent can reflect the effects of the user selection when it was created from an old instance of RequestHandler before the form was loaded. Here is the ShowForm method:
public void ShowForm(UIApplication uiapp) { // If we do not have a dialog yet, create and show it if (m_MyForm == null || m_MyForm.IsDisposed) { // A new handler is declared to handle request posting by the dialog RequestHandler handler = new RequestHandler(); // External Event for the dialog to use (to post requests) ExternalEvent exEvent = ExternalEvent.Create(handler); // We give the objects to the new dialog; // The dialog becomes the owner responsible for disposing them, eventually. m_MyForm = new ModelessForm(exEvent, handler); m_MyForm.Show(); } }
The handler and external event are then passed into the form and read into the form's private properties:
public partial class ModelessForm : Form { //Private properties of the form private RequestHandler m_Handler; private ExternalEvent m_ExEvent; public ModelessForm(ExternalEvent exEvent, RequestHandler handler) { InitializeComponent(); m_Handler = handler;//Private form handler property is set to match the argument passed from application m_ExEvent = exEvent;//Private form event property is set to match the argument passed from application }
Finally, when the user clicks a button, the MakeRequest() method is invoked, which sets the properties of the private handler that belongs to the form and then the event is raised:
private void MakeRequest(RequestId request) { m_Handler.Request.Make( request );//Set the handler property to reflect the user-selected option m_ExEvent.Raise(); DozeOff(); }
So here is my question. Why/How does the private form property m_ExEvent reflect the changes made to the private property m_Handler when it's raised? There is technically no inheritance or any other relationship between m_Handler and m_ExEvent. The ExternalEvent m_ExEvent is not created directly from the newly modified m_Handler. It's essentially just a copy of the old original event that was created from the old handler BEFORE the form was launched.
I've tested it and can see with my own eyes that it works properly, but I don't understand why m_ExEvent.Raise() automatically adapts to the updated m_Handler. Any suggestions as to why this is the case?
Solved! Go to Solution.