Passing a BusinessObject by reference


Author
Message
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
I want to pass a BusinessObject by reference into a method, as I want the BO changed in the method, and the resultant chnged BO available in the calling routine. I have set up a very simple method for illustration purposes(does not do anything)

TestMethod(ref KernelBaseSF.KernelBO myBO)
{ int x;  x=1}
(KernelBaseSF.KernelBO is my Subclass of the MicroFour.StrataFrame.Business.BusinessLayer)

 Now, the following does NOT give a compile error:
KernelBaseSF.KernelBO bo = new KernelBaseSF.KernelBO();
KEK001.TestMethod(ref bo);
However, if I try to use a BO thats dropped on the form as in:
KEK001.TestMethod(ref this.KmaBO1) 
 I get an Error 6 The best overloaded method match for 'KEKCommon.KEK001.TestMethod(ref KernelBaseSF.KernelBO)' has some invalid arguments C:\KEK\Kernel_App\Scp_Maint.cs 242 13 Kernel_App


If I just take out the ref parameter in the calling and called methods,it compiles ok, so it looks like there is an issue, for calling by ref, of a BO dropped on the form
Edhy Rijo
E
StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Gerard,
Besides the error, why would you want to pass the BO instance as a reference to another BO?
If you need the records in the current BO to be referenced in another BO you can pass your new bo sample and then use the bo.CopyFrom() to get the updated records.

Edhy Rijo

Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Edhy.

I have a routine set up as follows:

DoSearch(myBO,"VariousParameters")

Dosearch is a general purpose type  method which calls up a Devexpress grid  (I have made this general purpose so it uses the Database Table rather than a BBS) , and the various parameters are a 'TableDriven' utility to specify run time fields to appear in the grid. The net effect is thet the Row returned from the Grid is used to populate the BO within the DoSearch method.

In the calling program, I then want to end up on the particular row of the BO. This is why I want the calling BO referenced. The calling BO is going to be different each time. In the DoSearch method I have a general method (thanks to a previous reply from yourself)  which 'Fills' the BO in the DoSearch method.

If I was to use the boCopyFrom, I am not sure how this would work as the calling BO could be different each time.
Edhy Rijo
E
StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Gerard,
The BrowserDialog does the same thing, but each instance is specific to a BO so it knows what BO to populate when you drop it in the form.  You want basically the same but with the flexibility of somehow passing the BO and the method to execute.
Again, this approach is much more difficult since at some point you must know which BO type to work with.  Are you building some sort of Parameter Form or your own BrowserDialog form?

It is funny, that you mentioned DevExpress grid since this week I started to replace some of my StrataListView controls with the DevExpress GridControl.  There is a custom class in the SF Inherity project "Enhanced ListView" which basically takes the DevExpress gridcontrol and mimics the SF ListView with a datatable and list population events, in that source code you may find some useful code or approach for your control, it is very interesting.  In my case I am using the SF BBS since I found it easier to setup the GridControl with the BBS and also the BBS keeps the CurrentRowIndex of the BO updated so I don't have to add code to handle that.

Back to your control, are you sure you want this 100% generic or you can use the same approach of the Browser Dialog?  You can see the source code and add all the properties and methods that allows you to add the BO type at design time, etc. as it is done with the Browser Dialog.

Edhy Rijo

Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)Advanced StrataFrame User (628 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Edhy.

I have re-engineered my requirement slightly and rather than returning the BO, I just return the Key into the table, which works fine for the moment, and should be a lot simpler as no BO is involved.

I am in the process currently of trying to make the controls I use all the time as generic as possible. The specific control I am working on is basically for a lookup /grid, and I call a method with code like   Lookup(myBO, SerachString) . The Lookup then looks at the table name attached to the BO, and accesses another table to get DataDriven Field names,as well as a bunch of other parameters like Sortable, Total Column, Column Width etc.. I then use the DataDriven Field parameters to construct a Devexpress Grid, whcih is then used as either the Lookup, or a conventional Grid. This all seems to work quite well with not that much code behind it. 

The main reason I need this is,  that our users need to be able to decide on what columns they see in a grid...so it means that the user can decide whcih columns and how the columns appear.
Edhy Rijo
E
StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Gerard O Carroll (8/30/2011)
I have re-engineered my requirement slightly and rather than returning the BO, I just return the Key into the table, which works fine for the moment, and should be a lot simpler as no BO is involved.

Good I always try to keep things simple and easier to provide maintenance later on.

I am in the process currently of trying to make the controls I use all the time as generic as possible.

Me too.  As a consultant I try to re-use every class I can in all my projects so I can be handle things faster and more reliable.

The main reason I need this is,  that our users need to be able to decide on what columns they see in a grid...so it means that the user can decide which columns and how the columns appear.

I am new using DevExpress grids, but I believe you can have a standard layout and then you can save/restore the layout at runtime.  I use the RibbonBar a lot and there are some settings I save in the registry using SF SaveSizeAndLocation() and RestoreSizeAndLocation() of my main form, but I noticed in the Layout of GridControl Designer that you can Save it to an XML or Load it from an XML, I have not tried that yet, but that seems to be the easiest way to allow the end user to add customization to the gridcontrol, you can have a customization table linked to the SF User's table where you can store all your XML settings, this way it would be available to the End User from any workstation.

Edhy Rijo

Edhy Rijo
E
StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)StrataFrame VIP (4.5K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Gerard,
Looking at the DevExpress videos I came across to this one http://tv.devexpress.com/XtraGridSaveCustomizations.movie which shows you how to save/restore grid's layout views, it may fit your needs and very easy to implement.

Edhy Rijo

Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.4K reputation)Strategic Support Team Member (3.4K reputation)Strategic Support Team Member (3.4K reputation)Strategic Support Team Member (3.4K reputation)Strategic Support Team Member (3.4K reputation)Strategic Support Team Member (3.4K reputation)Strategic Support Team Member (3.4K reputation)Strategic Support Team Member (3.4K reputation)Strategic Support Team Member (3.4K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Not sure this would help, but here is an Infragistics inherited Grid I posted a while ago that saves its own position and layout.

http://forum.strataframe.net/FindPost27157.aspx
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