Access childBusinessObject


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Glad you are getting it figured out. BigGrin
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
If all of the children are of different types, then you will want to use a For Each loop to get the one you want like this:

For Each child As BusinessLayer In Me.ChildBusinessObjects
    '-- Test the type of the child
    If child.GetType() Is GetType(MyChildType) Then
        '-- Process the child
    End If
Next

Randy Jean
Randy Jean
StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)
Group: StrataFrame Users
Posts: 105, Visits: 641
Ben Chase (06/04/2007)
No, but I will add a property to expose that collection for the next release. In the meantime, you can add the property and rebuild the source code if you need it.




I'm feeling pretty confident now... I needed this too and actually got it to work no problem.



Question: in this case I had 1 child so I knew it was just Me.ChildBusinessObjects(0) to get my reference. I'm assuming I can loop through the collection checking for the name of the childbusiness object I need a reference to. Can someone post an example? I'm assuming it's a for loop of some type.



Thanks,

Randy
Randy Jean
Randy Jean
StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)
Group: StrataFrame Users
Posts: 105, Visits: 641
Figured it out. My relationship was invalid after renaming the parent class quite some time ago so I just had to reset the ParentRelationship. This is the problem with not being able to focus on one project at a time. So, it's all good now. Thanks for all the help.
Randy Jean
Randy Jean
StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)
Group: StrataFrame Users
Posts: 105, Visits: 641
Thanks Greg,

At least this code doesn't blow up and all seems to look good at design time. (and it's only a little more complicated than my VFP example BigGrin) However, my validation code is not running still as I suspected it would not because at runtime Me.ParentBusinessObject is in fact Nothing (or NULL)



So, maybe this is a different issue altogether. Any ideas why ParentBusinessObject would be Nothing if I have my Parent/Child properties set properly?
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Randy,



I can't answer your theoretical questions, but I might offer some insight into how to do what you propose in your code. The thing to recognize is that based on the code below, you know the type of the parent business object and the field you want to check, so strong typing becomes your friend BigGrin



Here is my suggestion at some .NET code. A couple of notes. First, I just typed this in, so there may be some spelling errors/syntax errors. I just wanted to give you an idea of how to do what you are trying to do. Second, Me is the object reference to the instance of a type in VB ('this' is used in C#). I've written this as if it was happening on a form, with a child bo named myChildBO. I've called the parent BO InsturmentBO. Any or all of that could be wrong...again I hope this gives you some idea of how it might be done in .NET.





'-- Validate that a parent BO is set

If Me.myChildBO.ParentBusinessObject IsNot Nothing then

'-- Cast parent BO to its actual type

Dim myParentBO As InsturmentBO = DirectCast(Me.myChildBO.ParentBusinessObject,InsturmentBO)



With myParentBO

'-- InsturmentName is now a strongly typed property, you make changes to your InsturmentBO

' and this will not compile...no hidden bugs

If .InsturmentName = "Atlas" Then

'-- Call validation code

End If

End With

End If





Finally, this works if you know what the parent BO type is and what the field name is. If you don't, then you could use this code instead:





'-- Validate that a parent BO is set

If Me.myChildBO.ParentBusinessObject IsNot Nothing then

'-- Can't cast the BO, but all BOs are wrapping an ADO.NET DataTable, which we can use

Dim myParentDataTable As System.Data.DataTable = Me.myChildBO.ParentBusinessObject.CurrentDataTable



'-- You can access any column via the rows.item property of a datatable.

' fieldName is a variable that is filled with the name of the column to check and

' validData is a variable to check it against. This likely would only work if you

' knew the data type of the validData, in this case I'm using a string.

If CType(myParentDataTable.Rows.Item(fieldName),String) = validData Then

'-- Call validation code

End If

End If





I hope this helps. I was pulling my hair out (what little there was to start with) when I started .net and SF about 7 months ago. Hang in there, there is light at the end of the tunnel (and it's probably not a train Blink ).
Randy Jean
Randy Jean
StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)
Group: StrataFrame Users
Posts: 105, Visits: 641
Trent L. Taylor (06/05/2007)
Randy,



You are kindof fighting against the grain of .NET and is more related to that versus SF.







I agree, but since I'm still learning both figured this is a better place to get real-world answers vs. theory.



b]Trent L. Taylor (06/05/2007)[/b]


Once you understand and begin to work within the strong-typed environment you will look back with utter disgust the weak-typed environment Smile ... I promise.




I don't know, all I can do is keep trying but I would say I'm still not even 10% as productive in .NET as I was in VFP. And it's not that I'm not OOP saavy - I use an nTier OOP framework for years. What I'm trying to do is as simple as:







IF TYPE("This.oParentBizObj") = T_OBJECT

With This.oParentBizObj

If .GetField("INSTRUMENTNAME") = "Atlas"

IF Not This.CallMyValidationCode()

*** update error collection...

endif

Endif

Endwith

ENDIF







Now, even though I don't get intellisense at design time I KNOW this will work or at least not blow up if oParentBizObj is not an object. .NET has to use fancy stuff like "Reflection" to pull of something "dynamic" like this. Not to start a debate, but I consider myself pretty smart and I've been nothing but frustrated whenever I try to do what seems should be straightforward and logical. Not to say I don't like some things about .NET, especially the improved forms and controls and how much easier it is to create a fancier screen.... but my bread and butter is in the business logic and data processing, not fancy screens. So it seems like not a very fair trade-off for me (yet)



So, I'm feeling really dense right now because I still have not "got" how to check a value in the parent bizobj from the child. I have a working parent/child screen so I know the stuff is set up correctly, I just can't figure out where/how to do what should be a simple check of a value in the parent from the child.



Also, I just pulled up the Strataframe source to see if I could "learn" from that (that's how I learned how best to use the VFP framework over the years) - I can't even pull up the Business Layer class in the designer. And when I did a rebuild all my reference to Microfour.Strataframe.Application is gone! And I still could not see how to reference the parent business object - What is _ParentBusinessObject?
Randy Jean
Randy Jean
StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)
Group: StrataFrame Users
Posts: 105, Visits: 641
This still doesn't solve my problem and more importantly does not work. I'm putting this in my child CheckRulesOnCurrentRow and ParentBusinessObject does not exist at design time so I cannot even compile this. It doesn't work putting this in the instance either.



If I try your code I get:



'InstrumentName' is not a member of 'Microfour.Strataframe.Business.BusinessLayer'



this is at design time so I cannot even compile.
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
Randy,

You are kindof fighting against the grain of .NET and is more related to that versus SF.  First of all, I too understand what is was to be weak-typed as I too came from VFP.  Once you understand and begin to work within the strong-typed environment you will look back with utter disgust the weak-typed environment Smile  ... I promise.  But you are right, there are a few things to learn. 

First, you are trying to use an operator (=) to test an object reference.  This doesn't work in .NET.  You need to respect the typed environment and remember that a string is an object too.  If you look at it's derived type it is actually an object.  So you will need to test on it like this:

If Me.ParentBusinessObject.InstrumentName.Equals("atlas") Then
End If

Randy Jean
Randy Jean
StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)StrataFrame User (171 reputation)
Group: StrataFrame Users
Posts: 105, Visits: 641
I tried this and it compiles but at runtime oParentBiz is NULL:





Dim oParentBiz As InstrumentSetupBO

oParentBiz = CType(Me.ParentBusinessObject, InstrumentSetupBO)

If oParentBiz.InstrumentName = "Atlas" Then

If Not CheckOnePortActive(Me.CurrentRowIndex) Then

Me.AddBrokenRule(PortSetupBOFieldNames.Activate, "Can only have 1 active port on Atlas.")

End If

End If


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