Recent

Author Topic: [SOLVED] Where to store your options of a program  (Read 11463 times)

Edson

  • Hero Member
  • *****
  • Posts: 1326
Re: Where to store your options of a program
« Reply #15 on: April 20, 2016, 05:47:39 pm »
If you want to use a simple INI file and to have the ability of change these options in a Dialog form, maybe you could use my ConfigFrame library: https://github.com/t-edson/ConfigFrame
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

mischi

  • Full Member
  • ***
  • Posts: 189
Re: Where to store your options of a program
« Reply #16 on: April 21, 2016, 08:02:22 am »
.plist is an XML file, you can read it with "Laz2_XMLCfg" unit for example. Since you're the only one who reads/writes those config files, you don't have to follow any rules. Just use a regular txt file and rename it to .plist, or leave it as .txt, it doesn't really matter. Perhaps an ini file will also do the job? It all depends on the data you want to save/load.
I do not agree at all. It is the sure road into later trouble, like rejection by Mac users, the app store, ... I really do not understand, why not use the recommended routines from apple (mainly CFPreferencesSetAppValue and CFPreferencesCopyAppValue)? No need for reinventing the wheel. In some cases, it is a major effort or even not possible to follow the apple guide lines, but the preferences are fairly straight forward. If this is too much for you and your program aims for general users, you should probably give up to support OS X.
MiSchi.
« Last Edit: April 21, 2016, 08:10:00 am by mischi »

balazsszekely

  • Guest
Re: Where to store your options of a program
« Reply #17 on: April 21, 2016, 08:18:44 am »
@mischi
Quote
I do not agree at all.
That's perfectly fine!  :)
Quote
I really do not understand, why not use the recommended routines from apple (mainly CFPreferencesSetAppValue and CFPreferencesCopyAppValue)? No need for reinventing the wheel.
@madref can use your "UPreferenceData.pas" unit if he likes, or choose @Edson solution.  It's up to him.

Quote
If this is too much for you and your program aims for general users, you should probably give up to support OS X.
I already gave up OSX support with Lazarus, I explained why many time before.
« Last Edit: April 21, 2016, 08:38:12 am by GetMem »

mischi

  • Full Member
  • ***
  • Posts: 189
Re: Where to store your options of a program
« Reply #18 on: April 21, 2016, 10:13:30 am »
Quote
Quote
If this is too much for you and your program aims for general users, you should probably give up to support OS X.
I already gave up OSX support with Lazarus, I explained why many time before.
Lazarus is not aiming for the general Mac user. That's why I do not vote that the Lazarus team should give up supporting OS X. But actually, it shows the level of frustration I wanted to warn and one should be aware of. In particular if you cannot follow the guide lines for whatever reason, it can easily turn into an uphill fight.

balazsszekely

  • Guest
Re: Where to store your options of a program
« Reply #19 on: April 21, 2016, 11:18:12 am »
Quote
Lazarus is not aiming for the general Mac user. That's why I do not vote that the Lazarus team should give up supporting OS X.
I did not suggest or imply that the Lazarus team should give up supporting OSX. Personally I found so many inconvenience, that I gave up developing a long time ago. That doesn't mean other people should give up as well. 
With that said, I detach myself from this thread and any other future Mac related threads.

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Where to store your options of a program
« Reply #20 on: April 21, 2016, 09:24:55 pm »
Well to make all discussions stop here's my solution:
Code: Pascal  [Select][+][-]
  1. ...
  2. uses ....,XMLConf;
  3.  
  4.  
  5. ...
  6.  
  7.   TForm_Options = class(TForm)
  8.     ......
  9.     BT_Apply: TButton;
  10.     .....
  11.     XMLConfig_DB: TXMLConfig;
  12.     procedure BT_ApplyClick(Sender: TObject);
  13.     .......
  14.     procedure FormShow(Sender: TObject);
  15.   private
  16.     { private declarations }
  17.     procedure SetColors;
  18.     ......
  19.   public
  20.     { public declarations }
  21.   end;
  22.  
  23.  
  24. .......
  25. ......
  26.  
  27.  
  28.  
  29. procedure TForm_Options.BT_ApplyClick(Sender: TObject);
  30. var cfgFile, Kleur, V, U : string;
  31. begin
  32.   //  cfgFile := GetPreferencesFolder + 'RefereeDB.xml' ;
  33.   cfgFile := UserDir + 'RefereeDB.xml';
  34.   if FileExists(cfgFile) then
  35.     DeleteFile(cfgFile);
  36.   case KleurPop of
  37.     Rood   : Kleur := '1';  // Rood-Rose
  38.     Oranje : Kleur := '2';  // Oranje
  39.     Blauw  : Kleur := '3';  // Blauw
  40.   end;  // case
  41.   V := Copy(Versie,1,1);
  42.   U := Copy(Versie,3,2);
  43.   XMLConfig_DB.Filename := cfgFile ;
  44.   XMLConfig_DB.Clear;
  45.   XMLConfig_DB.SetValue ('/RefereeDatabase/Version/Value', V);
  46.   XMLConfig_DB.SetValue ('/RefereeDatabase/Update/Value', U);
  47.   XMLConfig_DB.SetValue ('/RefereeDatabase/Setup/Color/Value', Kleur);
  48.   XMLConfig_DB.Flush;
  49. end;     // BT_ApplyClick
  50.  
And then you get this file:
Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<CONFIG>
  <RefereeDatabase>
    <Version Value="1"/>
    <Update Value="12"/>
    <Setup>
      <Color Value="3"/>
    </Setup>
  </RefereeDatabase>
</CONFIG>


Thanks everyone for the input
« Last Edit: April 21, 2016, 09:27:09 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

mischi

  • Full Member
  • ***
  • Posts: 189
Re: [SOLVED] Where to store your options of a program
« Reply #21 on: April 22, 2016, 03:53:03 pm »
GetPreferencesFolder would already be quite a bit better than userdir ;-)

Thaddy

  • Hero Member
  • *****
  • Posts: 18676
  • Jungle wars. And failing health it seems.
Re: [SOLVED] Where to store your options of a program
« Reply #22 on: April 22, 2016, 05:15:32 pm »
GetPreferencesFolder would already be quite a bit better than userdir ;-)
I agree. But he's  not listening or reading very well.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: [SOLVED] Where to store your options of a program
« Reply #23 on: April 22, 2016, 09:11:18 pm »
I used UserDir for testing purposes. This directory is easier to access.
And UserDir is not a function in Lazarus. That is GetUserDir
If you had looked the line above the userdir you would have seen that i have made it a comment.
So i DID listen  8-)
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

 

TinyPortal © 2005-2018