StrataFrame Forum

Passing BO as Parameter

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

By Thomas Holste - 8/20/2010

Hi there,

In my main project I have different BOs which I use. Now I am

trying something I can't get to work and need some advice.

I added a second project which will contain some classes which will be used in other projects too. Now I was wondering if I could pass a BO as a parameter to a class in this second project. For example:

Public class dogettitelsatz

Public Sub gogettitel(cTitel as string, oBO as ???)

...start searching for a specific record

End Sub

End Class

This class shall be instantiated in the main-project:

...Dim oTitel as new titelsatz

oTitel.dogettitel("1234567",gatitelBO1)

But I can't figure it out and I am asking myself, if this is just old VFP-habits and I should solve it any other way?

And I was wondering, if I would instantiate my "own" BO in the second-project, I could "use" the definition (Mapping) in my main-project and how this can be done?

Thanks a lot for your help

Thomas

By Ivan George Borges - 8/20/2010

Hi Thomas.

Try this:

Public Sub gogettitel(ByVal cTitel as String, ByVal oBO as MicroFour.StrataFrame.Business.BusinessLayer)

By Edhy Rijo - 8/20/2010

Hi Thomas,



Adding to Ivan suggestion, keep in mind that if you have custom methods and properties in your BO, you need to CAST it to the correct type so you can see and use those custom methods/properties.





Public Sub gogettitel(ByVal cTitel as String, ByVal oBO as MicroFour.StrataFrame.Business.BusinessLayer)

Using MyNiceBO as CTYPE(oBO,gatitelBO)

' Now you can see your custom methods/properties. Make sure you have the class gatitelBO available in your project.

End Using

End Sub

By Greg McGuffey - 8/20/2010

Adding to both Ivan and Edhy BigGrin ....



If the gogettitel will only work with BOs of type gatitelBO, then you could just do this:



Public Sub gogettitel(ByVal cTitel as String, ByVal oBO as gatitelBO)




I.e. you can skip the cast.



If you intended the gogettitel method to work with multiple types, that is also possible, but a bit more complicated.
By Thomas Holste - 8/21/2010

Hi Ivan, Hi Edhy, Hi Greg,

thank you for your tips but I am afraid to tell you that they do not work (Or at least I can't get it working?).

The reason probably is, that the BO and the Class are in different projects? And I can add a reference in my main project (containing the BO-definition) to the "class-project" but then not vice versa. So the main-project knows about the class, but the class not about the BO.

It is not really a problem because I added a new BO für the needed table to the class-project and everything is working.

Best regards

Thomas

By Ivan George Borges - 8/21/2010

Hi Thomas.

It should be a best practice to have all your BOs in a Business Object Library, the help file has a section on this right at the tutorials. And yes, given the needed care to the references, what has been showed here to you should work just fine.

But I'm glad you got it working, anyway. Wink

By Thomas Holste - 8/21/2010

Hi Ivan,

thanks for your tip, I'll try it right now.

Best regards

Thomas

By Ivan George Borges - 8/21/2010

You're welcome.

Let us know of the outcome.

By Thomas Holste - 8/23/2010

Hi Ivan,

thanks again for setting me in the right direction building a BO-library. That is exactly what I need.

Best regards

Thomas

By Ivan George Borges - 8/23/2010

Glad to hear that, Thomas!

You are most welcome. Cool