How to overload FillByPrimaryKey


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I have a base form that has a BusinessLayer property. I then call the FillByPrimaryKey method on this BusinessLayer property (which is of course set to some concrete BO).



I have a BO were I've overloaded the FillByPrimaryKey method (marked method in BO with "Overloads"). I thought that this would hide the FillByPrimaryKey method in BusinessLayer, but apparently it doesn't..my overload never gets called from the form, the one in BusinessLayer gets called. I must not be understanding how this should works... Unsure



How do I overload FillByPrimaryKey (or FillByParent, etc) so I can use a generic BusinessLayer (program to the abstract class/base class), but use the overload in a specific BO if needed?
Replies
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
OK, here is the deal.  If you are programming in VB.NET, which I think that you are, then you will either need to override (which as you mentioned these are not presently marked as overridable) or Shadow the method.  You will need to explicity assign the Shadows to you method or the BusinessLayer logic will be what gets called.

Public Shadows Sub FillByPrimaryKey(ByVal pk As Integer)
    '-- Place your logic here
End Sub

I just verified that what I am telling you is correct and it should work just fine.  Now it really wouldn't be a bad idea to allow these to be overridable anyway...so I will add this to the list.  If you can't get this worked out then let me know and I will make these overridable and post an update sooner rather than later.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Thanks for your replies. Yep, I use VB.NET. I just did some testing using the Shadows keyword (instead of Overloads) and the results are the same. To reiterate what I was trying to do:



- I have a base form that has a BusinessObject property (I probably should have used the PrimaryBusinessObject, but I wasn't that smart and added my own Blush ). It is of type BusinessLayer.



- This form also has an IdToLoad property (integer...I'm using integer PK always) that indicates the ID of a record to load.



- In OnLoad of this base form, I check if IdToLoad is > 0 and if it is, load that ID automatically via Me.BusinessObject.FillByPrimaryKey(Me.IdToLoad)



- For one of my BOs, I'm overloading the FillByPrimaryKey to add a couple of other columns. I used the Overloads keyword, but based on testing, the Shadows keyword would work the same. When I try to auto load by setting the IdToLoad, the call to Me.BusinessObject.FillByPrimaryKey(Me.IdToLoad) (and Me.BusinessObject is set to this BO with the overloaded FillByPrimaryKey) actually calls the FillByPrimaryKey method in BusinessLayer, NOT my overload. After getting my head wrapped around it, based on my testing, this is expected.



I've already fixed this, so in the case of the form using this BO, it skips the auto loading and instead uses the overloaded FillByPrimaryKey. So no rush on marking the FillByXxx methods with Overridable, though that will be a welcome enhancement.



A couple of last comments (for the lurkers BigGrin).

- The difference between Shadows and Overloads is that Shadows overloads all signatures for a method, were as Overloads only overloads the matching signature.

- While it was annoying that this didn't work, now that I understand it, it makes sense. Overloading in this fashion (as opposed to overloading a method's signature) hides base class functionality. The way this is implemented allows for both the new functionality and the base class functionality to be available, based on the type.



I'm including a solution that demonstrates all of this. It uses the StrataFrameSamples db. Thanks for the, as usually, outstanding help and for the future enhancement to mark these methods overridable.
Attachments
InheritanceTest.zip (196 views, 792.00 KB)
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