Edhy Rijo
|
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
Hi, In all projects I have tables like CompanySetup or WorkstationSetup where I save user/application settings, in my VFP applications I made heavy use of the _SCREEN.oSetup or _SCREEN.oWorkstation custom properties to hold the values for those tables using the VFP command SCATTER NAME _SCREEN.oSetup. In .NET/SF what would be the recomended way to create/have the same functionality of that data and make all those properties available anywhere in the application, like reports, forms, etc.? Thanks!
Edhy Rijo
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
This is the purpose of static or shared properties and classes. They are far better than global variables as they take no overhead unless they are referenced. You can add a static property to any class. Generally we have a class dedicated to items such as this. But in the StrataFlix sample I know there is a basics class or something along those lines. Public Class MyClass Private Shared _MyProperty As MyObject Public Shared Property MyProperty As MyObject Get Return _MyProperty End get End Property Public Shared Property MySecondProperty As String Get Dim r As String = "" Using bo As New MyBo() bo.FillWithData() If bo.Count > 0 Then r = bo.MyBOProperty End Using End Get End Property End Class That should give you a few ideas and examples of how to use static (or shared in VB) properties.
|
|
|
Edhy Rijo
|
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
Thanks, I know remember seeing something like that in StrataFlix, will investigate more.
Edhy Rijo
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
I've been thinking about this and I'm thinking that the way to go is to have BOs for the various settings (like general app, company settings, user settings, whatever). You could load the BO from an xml file using XMLBasics or from a db table. Then have a shared class called Settings (or something like that) that had shared properties for each of the BOs that actually manage the settings. The BO manages actually loading/saving settings, but access is very easy via the shared class: '-- Get some setting...Say how much verbage they want in messages!
Settings.User.Verbosity
'-- Or some app setting...Say the theme to use
Settings.App.Theme The actual settings are thus strong typed. Using the BO mapper allows easy changes to the settings. You would then provide a shared method to load the settings, which could use FillMultipleDataTables, called from InitApp (I think that is what it is called) of AppMain.vb or Program.cs. I haven't had a chance to try this for real, but sure looks appealing.
|
|
|
Edhy Rijo
|
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
Thanks Greg, I like the idea, specially since having the BO with strong typed properties it is easier to maintain, but in the shared class how would I loop trough the BO properties to create properties with the same name as the BO and assign their values to the newly created shared properties? I guess so sort of reflection here should be use?
Edhy Rijo
|
|
|
Peter Jones
|
|
Group: Forum Members
Posts: 386,
Visits: 2.1K
|
Hi Edhy, Yes, we went down the standard set of BO's road. We load them at init time in all programs into a class called clsRunTimeEnvironment and the running program just calls in and picks up whatever it wants out of that class. Cheers, Peter
|
|
|
Edhy Rijo
|
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
Peter Jones (02/26/2009)
Hi Edhy, Yes, we went down the standard set of BO's road. We load them at init time in all programs into a class called clsRunTimeEnvironment and the running program just calls in and picks up whatever it wants out of that class. Cheers, Peter Hi Peter, Thanks for the info, but are you manually creating all shared properties in your clsRunTimeEnvironment? or is there a way to loop the BO properties to create and assign the values into clsRunTimeEnvironment properties?
Edhy Rijo
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
..., but in the shared class how would I loop trough the BO properties to create properties with the same name as the BO and assign their values to the newly created shared properties? No need to do this at all. The shared properties of the global class ARE BOs (instances of them). From my example: Settings.App.Theme Settings is the global class used to access all settings. App is a shared property of type AppBO (which was built by the BOMapper and stores app specific settings). Theme is a strongly typed property that access the underlying data, via AppBO (it's a data property of the BO...built by BOMapper). To add a new setting, you update your db (however that works for you), open the BOMapper, configure the new field and rebuild the partial...boom, a new property is available. Does that makes sense?
|
|
|
Edhy Rijo
|
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
Greg McGuffey (02/26/2009) Does that makes sense? Yes, thanks. I did make sense and I got it done in no time, here is the resulting code: Imports CardTrackingSystem.BusinessPublic MustInherit Class AppSettings Private Sub New() End Sub '-- Set the Company Setting Object Private Shared _company As bizCompany Public Shared Property Company() As bizCompany Get Return _company End Get Set(ByVal value As bizCompany) Dim loBO As New bizCompany loBO.FillAllRecords() _company = loBO End Set End Property '-- Set the Workstation Setting Object Private Shared _workstation As bizWorkstation Public Shared Property Workstation() As bizWorkstation Get Return _workstation End Get Set(ByVal value As bizWorkstation) Dim loBO As New bizWorkstation loBO.FillAllRecords() _workstation = loBO End Set End PropertyEnd Class
Now I can reference the properties anywhere like this: AppSettings.Company.CompanyName = String.EmptyAppSettings.Workstation.WorkstationName = String.Empty Of course I have not tried this on reports yet, but there should be no problem
Edhy Rijo
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
Very cool! That's what I was talking about! Actually Charles Hankey got me thinking this way a while back, so thanks to him for the initial idea too.
|
|
|