ChildFormDialog & ParetnBusinessObject


Author
Message
Larry Caylor
Larry Caylor
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Awaiting Activation
Posts: 592, Visits: 3.7K
I had an issue with a parent/child object relationship. It's working now but I'd just like to understand what was going on.

Form 1
     Contains BO1
     BO1 is passed to Form 2 using a ChildFormDialog

Form 2
    Contains BO1 translated by CFD
    Contains BO2 (ParentBusinessObject set to BO1 in the designer)

At runtime the ParentBusinessObject property for BO2 is Nothing even though it was set to BO1 in the
designer. If I set the relationship in code on Form 2 everything works as it should. I'm assuning that the
translation of BO1 by the ChildFormDialog is messing up the relationship set in the designer.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Larry,



I can't find the posts I've done related to this, but here is my understanding.



In the designer file, in the InitializeComponent() method:

1. A new instance of BO1 is created and the pointer stored in your BO1 variable.

2. A new instance of BO2 is created and a pointer stored in your BO2 variable.

3. The ParentBusinessObject property of BO2 is set to BO1, or the pointer that is held in BO1 is stored in that property



During Form Load:

4. The translations happens from BO1 on parent form to BO1 on child form. I.e. the pointer that the BO1 variable holds is changed to point to the BO1 on form one. I believe that the translation will also handle updating the pointers used for binding, but it doesn't attempt to handle things like parent BO properties. I.e. the ParentBusinessObject of BO2 is still pointing to the BO1 that was created in InitializeComponent.

5. You then manually reset the ParentBusinessObject of BO2 to BO1 (which seems like you're repeating yourself, but the pointer stored by BO1 has changed).



Hope that is clear. My brain hurt for a bit until I got this figured out. Crazy
Larry Caylor
Larry Caylor
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Awaiting Activation
Posts: 592, Visits: 3.7K
Greg, Thanks for the analysis. I suspected that something like that was happening but I wanted to make sure I wasn't missing anything. We spent some time banging our heads against the wall trying to figure out why things weren't working the way we expected and then a light went on and we figured it had something to do with the fact that BO1 was being translated.  
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Glad to be of help. This one had me pretty confused for a while. There are some other good posts about this from Trent, but I couldn't (didn't take time to) find them.



We spent some time banging our heads against the wall trying to figure out why things weren't working the way we expected...




Yeah, the scab on my forehead from my run with this one just fell off the other day! Wink
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Because of this problem with the BO Translations, I decided to create my own ChilfForm Templates in which I include a comment to reassign the ParentBusinessObject in the OnLoad/Load event.



VS Templates are really a nice way to speed up the development process, in my case I am following the StrataFlix form's design with Panels, Themed Group Boxes, etc, and having a template with the standard code used in the childform simplifies things and I just need to delete the controls I don't need and move on.



Creating the template is very easy, simply click the "Export Template" from the "File" menu in VS and follow the prompts. I even have templates for my commonly use projects like Base, Business, Reporting, UI to startup new projects.

Edhy Rijo

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
Yup, Greg.  This is the very thing that we went through on the other thread.  I had trouble finding it also (didn't try too hard).  But in short here is the issue.  It has to do with the BO translations.  All of the translations get taken care of during the OnLoad of the form or user control.  All standard properties and instances get converted.  However, downstream instances to not get replaced, such as a BusinessObject property on a list.  This is because we do not reflect over every object and instance of every object on the form.  We update the BO references (components) and the ParentBusinessObject properties of the converted BOs, but we do not know about all of potential references, nor should we reflect over everything as this would be painfully slow.

So in these types of instances you do exactly what you did and update the instance in code AFTER the OnLoad base logic has executed.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Thanks Trent. I think that is the last piece (what exactly is getting translated) of the puzzle. For me (being a bit slow), it took a while for my brain to wrap around the "why", but once I got that, it all made sense. Larry, being the sharp guy he is, probably had this figured out a lot quicker than I did!



Great idea for the VS template Edhy! Better than my current "crap why didn't that work...???...oh, I forgot to set the BO after translation" method. Tongue
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