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
). 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
).
- 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.