StrataFrame Forum

Example of how to use a base form

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

By Greg McGuffey - 11/13/2007

This is an example of how to sub class the SF StandardForm to add functionality beyond what SF provides. I'm providing an example of some functionality that I needed, but of course, you may need vastly different features. Hopefully this might help in figuring out an elegant and pragmatic solution for you also!



I found myself very often coding the following features into a form:



- setting the title of the form to reflect the current record

- constructors that took the ID of a record that was passed to it, then loaded that single record into the form's BO.

- constructors that took a boolean that indicated I wanted to add a new record when the form opens.



I also need the ability to pass in a BO or data table with the data the form would use.



After doing this a few too many times, the light bulb went off and I realized there must be a better way. I then started to investigate how to use a base form. SF provided the example. The StandardForm inherits the SF BaseForm, which in turn provides all the SF niceness that we love. Why couldn't I do that myself and add my extra features? BigGrin



So, I coded a base form that added the features mentioned. Now when I need one or more of those features, I just inherit from my base form (which inherits from StandardForm...so I have the SF features too).



When the solution opens, an explanation page is shown that should help you get started.



For a savvy .NET developer, this is pretty basic stuff. However, a lot of us are moving from some other language/paradigm. So I thought I'd offer this up, as it might help to have a practical example of using a base class (plus some generic shared factory methods, how to hook into the SF events (see the OnLoad method)).



Of course, all of you savvy, svelte .NET gurus out there could certainly pipe in with suggestions for improvements or trade offs of doing things differently...I'm always learning more!



Thanks!

Greg Cool



P.S. You'll need the StrataFrameSample db loaded for this to work.
By Keith Chisarik - 11/14/2007

I would love to download this, thanks Greg.

When I click the link to download I am just taken back to the main forum listing page, right click and save as gives a .html page. I have tried in IE and Firefox.

I have had this issue with attachments for a while now. Help appreciated.

By Greg McGuffey - 11/14/2007

Hmmm....that is weird. I have no problem with the attachment. Anyone else? Maybe its a setting in IE/firefox or a proxy issue?
By Teddy Jensen - 11/14/2007

I have downloaded the attachment with IE without any problems.

And Greg - it is a very good sample with some functionality that i can use in my current application.

Thx.

Teddy

By Richard Keller - 11/14/2007

For those who may not know.  You can get tricky and add it to the New Item dialog as well via Templates as well.   Just search VSTemplates or look in C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates\  for some samples.

Richard

By Keith Chisarik - 11/14/2007

I was able to download from home, thanks Greg.
By Ivan George Borges - 11/14/2007

Hey Greg.

Very nice!

Thanks. Wink

By Michael Reese - 11/15/2007

I got it. Make sure you are logged in before downloading!
By Greg McGuffey - 11/15/2007

Glad it turned out that simple of a problem!