Topic: Create Default Settings

If anyone could please help? I'm trying to create a Setup screen where the user can select default settings, so that when the from is opened the defaults are already shown, but can be changed at anytime via default set up form. example select :- Fahrenheit or Celsius, Meters or Feet, with a dropdown with a selected value. any help would be appreciated.

Post's attachments

Attachment icon DefaultSettings.zip 340.9 kb, 241 downloads since 2021-09-25 

Re: Create Default Settings

It is necessary to create a DefaultSettings table and store one record in it with the default settings. You can open the DefaultSettings form like this:

procedure Form1_Button2_OnClick (Sender: TObject; var Cancel: boolean);
begin
  if SQLExecute('select count(*) from DefaultSettings ') = 0 then
    SQLExecute( 'insert into DefaultSettings (id) values (1) '); // add record with ID=1
  DefaultSettings.ShowRecord('DefaultSettings',1); // open record with ID=1
end;
Визуальное программирование: блог и телеграм-канал.

Re: Create Default Settings

I recently adopted this kind of setup.

You can also use the TIniFile

Here, I made some changes with your example.

Post's attachments

Attachment icon DefaultSettings2.zip 554.9 kb, 255 downloads since 2021-09-25 

brian

Re: Create Default Settings

I'm not sure to where you want the default settings to appear, when creating new record? it seems your button on Form1 is just a Show Form.

Anyway, for further samples, you can have a global variable which will be available to all your functions/procedures within your script that will handle the defaults.

Post's attachments

Attachment icon DefaultSettings3.zip 556.81 kb, 252 downloads since 2021-09-25 

brian

Re: Create Default Settings

Thank you Brian for having a look at my project and taking the time to wright some code I appreciate it. I was trying to have the default settings appear on the Jobsite form once they have been set up. Its early morning here so I will have a play with what you have done and see if I can get it to work.
Thanks

6 (edited by derek 2021-09-25 23:04:01)

Re: Create Default Settings

Hi Corey, Brian, Konstantin,

A different approach might be to simply hold a 'user default' field on each table where you want a default setting to be pre-set;  the default setting can be changed by the user. 
In the attached example, all new records take the user default settings, all existing records display the settings that were valid at the time they were created.
I'm not sure how often you envisage these default settings being changed (if at all) once they've been set but you need to exercise caution if they can be amended as it could get confusing with a mix of units.  Or do you plan to re-work all the old entries and convert them?
I'd also look at making use of parent comboboxes so that choices are more structured for the user.
I changed your project around a bit so I could more easily see what was happening but the principles are the same.
Derek.

Post's attachments

Attachment icon DefaultSettings 4.zip 341.62 kb, 269 downloads since 2021-09-26 

Re: Create Default Settings

Thank you all so much, I think that I may have over complicated things I created the DB as a sample that I would include into my project and yes I suppose it is a bit confusing. I apologise.  Derek you are so close to what I am after,  The Jobsit form on open where it has values already saved, and the dynamic labels are shown. is it possible to change via checkbox, on a separate form so for example if the user measures Pipe in ft or mtr they just type 100 and the label choice has already been selected in the setup/ default form. so when they enter there value the label is already showing as (ft) and the dropdown shows as Hot. like installing new software where you select English or French  once its set up the user would very unlikly change and if they do its only the label. If I can send you a copy of my project it would make a lot more sense on where I am gong and how I have over complicated things sorry.

Re: Create Default Settings

derek wrote:

Hi Corey, Brian, Konstantin,

A different approach might be to simply hold a 'user default' field on each table where you want a default setting to be pre-set;  the default setting can be changed by the user. 
In the attached example, all new records take the user default settings, all existing records display the settings that were valid at the time they were created.
I'm not sure how often you envisage these default settings being changed (if at all) once they've been set but you need to exercise caution if they can be amended as it could get confusing with a mix of units.  Or do you plan to re-work all the old entries and convert them?
I'd also look at making use of parent comboboxes so that choices are more structured for the user.
I changed your project around a bit so I could more easily see what was happening but the principles are the same.
Derek.

Your solution is more elegant in terms of coding and queries. But in terms of data normalization, I would rather store references to values.

Визуальное программирование: блог и телеграм-канал.

Re: Create Default Settings

brian.zaballa wrote:

...You can also use the TIniFile...

The TIniFile file solution is good if you need different default settings for each user in a multi-user version of the program.

Визуальное программирование: блог и телеграм-канал.

Re: Create Default Settings

Thanks to everyone for your help and suggestions. I am new to MVD and not 100% up there with the the coding side of things possibly only at  2%, I have tried to implement everyone's suggestions but with out any luck as I mentioned I may have overcomplicated what I was after I have attached a simpler example. Thanks again to everyone for their time and suggestions.  I hope you can help thanks

Post's attachments

Attachment icon BasicDefault Settings.zip 340.12 kb, 229 downloads since 2021-09-27 

11 (edited by derek 2021-09-27 18:04:48)

Re: Create Default Settings

Hi Corey,
Don't worry about being new to MVD - we all were at one point!
With respect, I still think you're over-complicating things;  if I understand correctly, all you're trying to do in your post is allow the user to set which temperature scale is the 'default' and then that default scale should be automatically displayed in a label on Form1. 
As such, there isn't any need for comboboxes with Options1 and 2 etc, multiple checkboxes and discrete labels for whatever scale is chosen.
Have a look at the attachment as a (hopefully) more straightforward approach.  Note how it is 'data driven' rather than 'code driven' - in other words, the user can change defaults, add, change and delete temperature scales etc without the programmer needing to get involved with adding new hidden labels, new checkboxes etc.
Referring back to your original post, you can do exactly the same thing with 'measurements'.
Shout out if anything's unclear.
Derek.

Post's attachments

Attachment icon BasicDefault Settings2.zip 337.11 kb, 282 downloads since 2021-09-27 

Re: Create Default Settings

Thanks Derek, once I get home from work this evening I will upload my actual project , and maybe you can also offer advise on saving three from as one record

Re: Create Default Settings

OK unable to attached is my actual project, please find a link to dropbox https://www.dropbox.com/s/fggyq2szwgxq5 … 1.zip?dl=0
If you select the first button New fishing trip under (water Type) By selecting Saltwater it will hide all Freshwater
fishing spots and locations edit box. What I wanted the user to select their preference in a set up screen as some people my only ever do one type of fishing.
2. by clicking on (Settings) then (SetUp) where weights, measurements and temp, these labels are show throughout the program and i wanted labels to show the  relevant scales.
3.If you are able to offer any advice on Linking all 3 Forms (New fishing trip, Conditions and Fish caught) so its all recorded as one record. hope this all makes a bit more sense.
Thanks for all your help.

14 (edited by derek 2021-10-01 17:33:31)

Re: Create Default Settings

Hi Corey,
There are a few different ways to do what you're after;  as always, I'd keep it as simple as possible.
Have a look at the attached as one option.
https://app.box.com/s/nf4yp6y3hqk5rw8tklz8nxfd2vayk3vi
Basically, I hold the user defaults (for temperature, wave height etc) in a table (userdefaults) and load these values in as global variables to the script.  Then, wherever the label needs to show the appropriate default value, it just loads it from the relevant variable to the label's caption (there's no need for different labels for each value).
I've amended your 'mensetup' form with the changes.  Rather than over-complicate it, it just allows the user to enter such values as they want as default and uses field 'hints' to guide the user accordingly.
With regard to 'watertype' and displaying / hiding options depending on whether 'saltwater' or 'freshwater' is selected, I think you should look to use 'parent combobox' functionality (part of standard MVD) rather than trying to achieve it in the script.  As I said in an earlier post, the more you can make your program 'data driven' the less you need to be scripting.
Derek.

Re: Create Default Settings

Thanks to Brian, K245 and Derek, for your help suggestions and time, Derek thank you again that works better than I thought, you have helped me so much already with this project, but I'm going to push my luck and ask one last thing. is there a way to save those 3 forms (New fishing trip, Conditions and Fish caught) as 1 record
I don't expect you or anyone else to write the codes but if you could please point me in the right direction
it would be greatly appreciated. I will give you all a break after this one.

Re: Create Default Settings

Hi,
The easiest way is to put everything onto one form.
And the easiest way to do this is to use panels so that it still looks like you're moving between forms.
https://app.box.com/s/dzsahu20t5axne6cw4dn4s53zpbjpffj
In the attachment, 
1.  everything that was on 'NewFishingTrips' form has been placed onto Panel1 (simply 'select all' / cut / add an appropriately sized panel / paste everything back on).
2.  create two new Panels
3.  copy (in the same way as above) everything off 'Conditions' form and paste it onto 'NewFishingTrips' panel2
4.  copy everything off 'Fishcaught' form and paste it onto 'NewFishingTrips' panel3
5.  set panels 2 and 3 to invisible
6.  reassign your 'next' and 'back' buttons to make the appropriate panel visible / invisible.
If you overlay the panels, the effect is much like moving from form to form but now it's straightforward to save everything that is on all 3 panels with just 1 'save' button.
nb:  when you open the attachment, just increase the height of  'newfishingtrips' form and you'll see each panel overlayed - to access each panel, just use the 'bring to the front' or 'send to the back' options
I've moved the 'next' and 'back' buttons so that they are consistently placed but it's just cosmetic.
Derek.

Re: Create Default Settings

Derek again thank you very much for your help, I had no idea how I was going to link those 3 forms that worked perfectly. Thanks  smile