Question: Original BO and subsequent copies


Author
Message
Ben Hayat
Ben Hayat
Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
a) I create a BO in a project and then I build the project. The BO appears on the Toolbox.

b) I then place a copy of the BO from Toolbox and put on my form.

c) I add some events to the original BO.

d) I add some events to the copy of my BO on the form.



Is it the correct understanding that SF will always execute the event's codes on the original BO first and then on any subsequent BO that were placed on the forms?



Thanks!

..ßen
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
The order in which a BO is dropped on a form has nothing to do with it actually...unless you ignore the INitializationPriority property.  You can get more specs on this in the help, but you can set the InitializationPriority property on a BO and actually control which order in which they initialize.
Ben Hayat
Ben Hayat
Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
Ok, I went ahead and put MessageBox on the main BO in the "BeforeSave" event and also a MessageBox the form's BO "BeforeSave" and I left the InitializationPriority=50.



I run the app and I see the MessageBox in the original BO shows first and then the one the form.



I then changed those value to 1 and 100 and vice versa, and still see the original BO gets executed first.



My question was mainly related to the order that which BO events get fired first (The main BO or subsequent ones) and not how it gets initialized on the form.

Thanks!

..ßen
Ben Hayat
Ben Hayat
Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
I got the following from the help and makes sense for setting and over writting properties:

A business object is a component, and therefore, utilizes .NET's Component Designer. Because of this, there are two differet places for you to configure a property on a business object: the Component Designer and an a business object instance's property sheet in a form designer. A change to a business object in the Component Designer affects all instances of that business object and is known as a "class-level" change, while a change to the property sheet of an instance of a business object only affects that instance of the business object and is known as an "instance-level" change.



Many changes to business objects should be made within the Component Designer for that business object as you do not want to have to make the change every time you drop a new instance of the business object on the form. You can, however, override any property on a business object either through the business object instance's property sheet or programmatically at runtime.





Can the events be over written, or the BO Components gets fired first and then the Instance?

..ßen
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
I guess I did not ask which events you were referring to.  The events are fired in the order of the BusinessObjects collection on the form.  If you refer to the BusinessObjects collection on the form, this is the order in which the BOs are going to fire the events.

The InitializationPriority has to do with instantiation order basically.  It controls the order that the ParentFormLoading event is fired.

Ben Hayat
Ben Hayat
Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
Trent, thanks for the reply; However, I think I have misled you with my question. Let me try it differently.

The two BOs that I'm referring to, are NOT on the form.



First I created my CustomerBO in the project which is basically considered as the CustomerBO Class.

Then I placed a copy of that CustomerBO from the toolbox on my form CustomerBO1.



My question is, when event on CustomerBO1 is fired (i.e. BeforeSave), does the same event on the CustomerBO Class is fired FIRST?

..ßen
StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Any events that are shared by the form and by the business object (like BeforeSave) are called on the business object first.  However, when you have a BO class defined in your application, the event is only raised on the instance, not within the class.

However, I think you might be talking about your event handlers for that event... if you handle the event in both your CustomersBO class and on the form where you dropped CustomersBO1, then most likely, the handler within the class will be invoked first.  However, with event handlers, you can never be assured what order they will be invoked in (because a multicast delegate does not keep track of the order of the handlers), so, when you want to handle an event within the class that declares it, you will almost always want to override the On"EventName" method instead of actually "handling" the event.  This way, you can control whether your code within the class will be executed before or after all of the handlers on the event.  The actual call to the base method will raise the event, so you can place it at either the top, the bottom, or somewhere in the middle of your overriding method, and the event will be raised then.  Like this:

Protected Overrides Sub OnBeforeSave(ByVal e As BeforeSaveUndoEventArgs)
    '-- Call the base method to raise the event before the code in this method is executed
    MyBase.OnBeforeSave(e) '-- The event will be raised here

    '-- Do any extra code

End Sub

The OnEvent() definition is standard .NET coding practices, so just about any time you want to handle an event in a derived class you'll want to override that instead.

StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
By the same token, since the OnEvent() methods are protected, you can call them (if you need to) to tell the base class to raise that event.
Ben Hayat
Ben Hayat
Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)Advanced StrataFrame User (570 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
Ben Chase (03/16/2007)
Any events that are shared by the form and by the business object (like BeforeSave) are called on the business object first. However, when you have a BO class defined in your application, the event is only raised on the instance, not within the class.



However, I think you might be talking about your event handlers for that event... if you handle the event in both your CustomersBO class and on the form where you dropped CustomersBO1, then most likely, the handler within the class will be invoked first. However, with event handlers, you can never be assured what order they will be invoked in (because a multicast delegate does not keep track of the order of the handlers), so, when you want to handle an event within the class that declares it, you will almost always want to override the On"EventName" method instead of actually "handling" the event. This way, you can control whether your code within the class will be executed before or after all of the handlers on the event. The actual call to the base method will raise the event, so you can place it at either the top, the bottom, or somewhere in the middle of your overriding method, and the event will be raised then. Like this:



Protected Overrides Sub OnBeforeSave(ByVal e As BeforeSaveUndoEventArgs)

'-- Call the base method to raise the event before the code in this method is executed

MyBase.OnBeforeSave(e) '-- The event will be raised here



'-- Do any extra code



End Sub



The OnEvent() definition is standard .NET coding practices, so just about any time you want to handle an event in a derived class you'll want to override that instead.




Ben, thank you for getting my point. What you described is what I was actually trying to discover/uncover for myself.

Great explanation. Thank you!



This product is deep... Got a lot to learn. I hope I can make it to training class!

..ßen
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
I hope I can make it to training class!

I hope you can make it....it is definintely worth the time and money!!!!

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search