StrataFrame Forum

Adding or Editing put me into an infinite loop

http://forum.strataframe.net/Topic19116.aspx

By Marcia G Akins - 9/5/2008

Hi All.

Me again. I have a form that is using the Browse Dialog to locate records. This form also has a DataGridView that holds the contacts for the current Advisor. This Code works fine:

private void brwAdvisor_BrowseDialogClosed(MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialogClosedEventArgs e)

{

// Get all the contacts for the currrent Advisor

boAdvisorContacts.GetAdvisorContacts(boAdvisor.advisor_pk);

}

However, when these 2 methods are left uncommented, they put me into an infinite loop - any ideas about why this is happening? I have another form that uses similar code to update the child records in the grid and there are no problems with it - the only difference between the two forms is that the one that works does not use the Browse Dialog. Here are the methods that are causing the problems:

private void Advisors_FormNavigated(MicroFour.StrataFrame.Business.NavigatedEventArgs e)

{

// Get all the contacts for the currrent Advisor

// if (!boAdvisor.IsEmpty)

// boAdvisorContacts.GetAdvisorContacts(boAdvisor.advisor_pk);

}

private void Advisors_FormEditingStateChanged(MicroFour.StrataFrame.Business.EditingStateChangedEventArgs e)

{

// if (!boAdvisor.IsEmpty)

// {

// if (boAdvisor.EditingState == MicroFour.StrataFrame.Business.BusinessEditingState.Idle)

// grdContacts.Enabled = false;

// else

// grdContacts.Enabled = true;

// }

}

TIA

By Marcia G Akins - 9/5/2008

Here I am talking to myself again Hehe

I suppose that the only time I need to worry about it is if I start giving myself the wrong answers Smile

The infinite recursion stopped when I moved the code to the corresponding boAdvisor event handlers. I have no idea why fixed the problem. Can anyone enlighten me?

Thanks

By StrataFrame Team - 9/5/2008

Yes, ma'am.  The business objects fire their Navigated event when they are refilled.  So, your call to boAdvisorContacts.GetAdvisorContacts(boAdvisor.advisor_pk) looks like it's populating the boAdvisorContacts business object; at the end of that fill process, it will fire its Navigated event.  The form's Navigated event is a mirror of the Navigated event of all business objects on the form... any business object navigates, and it gets raised as well.  So, when you filled your business object, it Navigated, which caused the form to raise Navigated, which filled the business object again, which Navigated again, which caused the form to raise Navigated again, and so on.  When you want to target the navigation of a specific business object, then use the Navigated event of that specific business object; just like you figured out Smile

As for the second handler on the EditingStateChanged, I'm not sure why that one would cause an infinite loop.  You're just enabling/disabling some UI elements, and not doing anything that would raise the EditingStateChanged again.

By Marcia G Akins - 9/5/2008

Ben Chase (09/05/2008)
The business objects fire their Navigated event when they are refilled.  So, your call to boAdvisorContacts.GetAdvisorContacts(boAdvisor.advisor_pk) looks like it's populating the boAdvisorContacts business object; at the end of that fill process, it will fire its Navigated event.  The form's Navigated event is a mirror of the Navigated event of all business objects on the form... any business object navigates, and it gets raised as well.  So, when you filled your business object, it Navigated, which caused the form to raise Navigated, which filled the business object again, which Navigated again, which caused the form to raise Navigated again, and so on.  When you want to target the navigation of a specific business object, then use the Navigated event of that specific business object; just like you figured out Smile

Thanks for the explanation. I appreciate it. Is there anywhere that I can find detailed information about the Strataframe's event model?

Ben Chase (09/05/2008)
As for the second handler on the EditingStateChanged, I'm not sure why that one would cause an infinite loop.  You're just enabling/disabling some UI elements, and not doing anything that would raise the EditingStateChanged again.

Well all I know is what I observedSmile

By StrataFrame Team - 9/5/2008

Is there anywhere that I can find detailed information about the Strataframe's event model?

The help documentation has a list of events that exist on the business object and descriptions/examples of them.  As for the form events, they're listed, too, but almost every one of them is a mirror event of the BusinessLayer class.  The business object raises its event and the form follows suit.  I don't think we have a diagram in the help documentation.  There a diagram of the save process in the documentation for our training classes and it shows events, but that's about it.

Well all I know is what I observed Smile

It could be that enabling the grid caused the IEditableObject.Edit() method to be called which would raise the EditingStateChanged, but setting the Enabled to true when it's already true shouldn't cause it to be called again.  Ermm

By Marcia G Akins - 9/5/2008

Ben Chase (09/05/2008)
[quote]Is there anywhere that I can find detailed information about the Strataframe's event model?

It could be that enabling the grid caused the IEditableObject.Edit() method to be called which would raise the EditingStateChanged, but setting the Enabled to true when it's already true shouldn't cause it to be called again.  Ermm

After my meeting with the client, I will try to track this one down and get back to you on what was going on. I meet with the client on Sep. 12th  so you will hear from me after that. Until next week, I am under the gunw00t