The Default Manager Class was created to provide a uniform method of storing and retrieving default settings. There are four levels of default storage; Registry, User Global, Window Global and User Global.
It really is as simple as all that. Two method, GetDefault and SaveDefault. We use it for everything! Storing database setting in the registry? Handled! Company wide preference for print preview? Handled! Default the last parameters settings for report so that the next time a user runs the report it remembers the settings, even if they run it from a different computer? Handled! Its deceptively simple, and nothing that can not be done in procedural code, but it sure is nice and gets used a lot more when all the developer has to do is say GetDefault and SaveDefault with 3 little parameters and let the magic happen.
Enough of a sales job. I hope you enjoy it. If you have any questions, suggestions, complaints (well not complaints) then please use the comments below so we can all benefit from each others additions. This article will be updated with each new release of the class.
Note there are references in the class to the SystemLogClass, which is a class I use to record all user error messages for later support. That class is not fully ready for the world but since WX doesn’t provide a way for me to set optional compile directives so that you don’t get compile errors for the references to the other class, I have included it in the zip for now. As long as it is in your project you are fine, if you don’t instantiate it it will not be used. If you want to use it you are more than welcome to but there is no documentation and it has not be fully fleshed out just yet. Your other option would be to remove or comment out the lines of code related to the System Log class, there would be no adverse effect on the Default Manager class.
A Note about code bricks. There isn’t a method of using multiple code bricks files or sharing just partial code bricks. What I will be doing is sharing my collection of code bricks, there are three files that make up the code bricks. Simply put them in a directory on your system and then from WX you can edit the environment settings and point to that code brick directory. And then copy those code bricks into your normal code bricks files. What I find works best is to have two copies of WD open, each pointing to a different code brick directory.
If you have any questions about the NextAge Open Source initiative be sure to check out this post.
The Download Links
Class and Documentation in a Zip File
Demo App with example code for all NextAge Open Source Class plus other bits and pieces
Change Log
1.0 – December 25, 2012
Initial Release
1.01 – January 16, 2013
- Rename Local Instance of SystemLogClass to TheSystemLogClass to avoid intellisense issues.
- Ability to store Binary Data – Thanks to suggestions from Pragma Tix.
- Corrected issue with the Assignment of Window Name not being correct if called from within a control’s code process.
- Fix for initial creation of Registry Key
1.02 – June 5, 2015
- Added New Constant SystemGlobal to allow store data that is global for the entire application regardless of user or window
- Added Support for a .config file
[suffusion-the-author display=’author’]
[suffusion-the-author display=’description’]
Hi Pete,
Thanks a stack for sharing this.
The codebricks zip file seems to be empty ?
LikeLike
Thanks Val,
Sorry about that, I have updated the Code Bricks zip file and they should be there now.
LikeLike
Hi Pete
Thanks for your great posts.
Just went to have a peek at your Code Bricks, but could not open the BDC.fic file as it seems to have a password on it.
LikeLike
Wolfgang,
Read the notes above about code bricks. They are a pcSoft file. You have to put them in a directory, and then go into the IDE environment configuration and point to them. Unfortunately they haven’t given us a method of easily sharing or merging code bricks. From the online help at http://doc.windev.com/en-US/?9000066
configure the directory of code bricks in the options of the product used (“Tools .. Options .. General options of WinDev/WebDev/WinDev Mobile”, “Directories” tab).
LikeLike
Hi Pete, great work (as usual), But I wonder how to deal with complex data types classes, structures etc.
I would suggest to introduce this enhencment ( or something similar)
For instance :
LabCon is connection
b is buffer
Serialize(LabCon, b, psdBinary)
DM.Save( PROJECTWIDE, “LabCon”, b )
//class DM method save
FUNCTION GLOBAL Save ( LOCAL storageType is int, LOCAL name is
string, LOCAL value )
//using a little bit runtime- reflection .
SWITCH Typevar( value )
CASE wlBuffer
// Save whatever we have serialized before into a BLOB/
bytea column !!
// etc..
END
Hope you will implement this feature and remain with best regards,
#pragma
LikeLike
Hi Pete
Thanks for pointing out the Code bricks “funny” to me again. I should have known better, as I have ran into this exact same problem some time ago. Beside running into this problem myself, you have also made it clear within your article. Just me again having a moment…!
LikeLike
Version 1.01 has been posted with a few fixes and the addition to support binary and structured data thanks to the suggestion from Pragma Tix!
LikeLike