State injection...

Topics: CAB & Smart Client Software Factory
Feb 2, 2006 at 3:16 PM
originally posted by: Agda

hi all,

this is my first post, I have been using CAB for the last few days and i guess a i'm a big CABNOOB... :s
Here is my question…
let’s say I have something like this on my smartpart…

public FooBar SelectedItem
return _selected;
_selected = value;


My question is… will this property be updated if the state is changed by another smartpart, or do I need to use the StateChaged?
Feb 4, 2006 at 5:10 AM
originally posted by: DLorenz

The state will change. The WorkItem, SmartParts, and Controllers reference the memory address of the item. If you change the state in a SmartPart, then it will be changed on the WorkItem, and anything else that is referencing that variable thru state. In fact, it will even change the parent workitem's state as well, assuming it passed it down to the child workitem.
Feb 4, 2006 at 7:02 AM
originally posted by: WalkingDisaster

I think it would be good to clarify that this is true for reference types. It is not true for volitile value types (primitives and structures).
Feb 4, 2006 at 8:47 AM
originally posted by: DLorenz

Ah, true.
Feb 9, 2006 at 5:09 AM
originally posted by: DotNetRules

DLorenz, I modified the BankTeller app to see how child state can update parent state but to this point haven’t been able to make it work.

I added a textbox to the CustomerQueueView and bound Customer-FirstName to it and added the state attribute:

<State()> _
Public WriteOnly Property Customer() As Customer
Set(ByVal value As Customer)
innerCustomer = value
End Set
End Property

In the load event I add the customer object to the BindingSource:


I then modified the WorkWithCustomer method in the BankTellerWorkItem to include the customer state:

Me.State(StateConstants.CUSTOMER) = customer

The app runs as it normally would however the textbox on the CustomerQueueView isn’t populated when you click on a customer in the queue, nor is it updated when a change is made in the detail view. I would have though BankTellerWorkItem being the parent workitem it would be notified of state changes in child workitem(s).

Any thoughts?

Feb 9, 2006 at 5:13 AM
originally posted by: DLorenz

Well, you cant change the reference of state, otherwise the Parent will ignore it. You can modify state in a child and the parent will reflect it. However, once you change the reference to something else, you will no longer update the parent's state.
Feb 9, 2006 at 5:36 AM
originally posted by: DotNetRules

Thanks for the reply. The child has the same reference as the parent or am I missing something obvious, I've been reading the cab doco in particular ‘Working with WorkItems’ topic which show examples of storing the same reference in the parent state and passing it down to the child workitem state.

Public Sub ShowCustomerDetails(ByVal custmr As Customer)
' set state for injection into child WorkItem
State("Customer") = custmr
Dim myChild As ChildWorkItem = Me.WorkItems.AddNew(Of ChildWorkItem)()
End Sub
Feb 9, 2006 at 6:30 AM
originally posted by: DLorenz

Well, if passing down the reference doesn't work, you can always do this in the child workitem:

protected overrides OnRunStart().. (or whatever it is)
Me.State("Customer") = Me.Parent.State("Customer")