Click to See Complete Forum and Search --> : saving opl program preference data


brianh
10-26-2002, 07:16 PM
I am currently developing a number of OPL applications. Right now each is close to being finished and would be better served if preferences could be saved.

Does anyone know how this is done using OPL code? Examples of source code or links to a site with info would be much appreciated.

Thanks in advance.

ktkawabe
10-27-2002, 04:17 AM
Hello Brian,

One of the easiest approaches is probably to create an OPL database, in which you could store anything you want. The code below (though VERY simplistic) is just to give some basic idea:

PROC InternalizeInifile:
  EXTERNAL version$(255), username$(255), age%, inifile$(255)
  IF NOT EXIST(inifile$)
   CREATE inifile$, A, version_ini$, username_ini$, age_ini%
   APPEND : DoInitialization: : UPDATE : CLOSE
  ELSE
   OPEN inifile$, A, version_ini$, username_ini$, age_ini%
&nbsp;&nbsp; IF A.version_ini$ <> version$
&nbsp;&nbsp;&nbsp; DoWhateverUpdateNeeded:
&nbsp;&nbsp; ENDIF
&nbsp;&nbsp; username$=A.username_ini$ : age%=age_ini%
&nbsp;&nbsp; CLOSE
&nbsp; ENDIF
&nbsp; RETURN
ENDP

PROC ExternalizeToInifile:
&nbsp; EXTERNAL version$(255), username$(255), age%, inifile$(255)
&nbsp; OPEN inifile$, A, version_ini$, username_ini$, age_ini%
&nbsp; MODIFY
&nbsp; A.version_ini$=version$
&nbsp; A.username_ini$=username$
&nbsp; A.age%=age%
&nbsp; PUT : CLOSE
&nbsp; RETURN
ENDP

Please note that you have to write DoInitialization: and DoWhateverUpdateNeeded: by yourself. By the way it's better to use the DBMS-style commands (because, for example, you can give names to the fields), but I cannot recall the syntax immediately. Please see the OPL manual.

I personally prefer to store everything in plain text, but this has a drawback of having to write a text parser by yourself. You can find a working code in my XJMail source package:
http://www.hi-ho.ne.jp/~ktkawabe/densha_e.html
See IniReader%:, POPSettingReader%: and such.
This stores everything in plain text in a form of
key=value
like

POP_USER=ktkawabe
POP_REJECT_BY_SIZE=1
EXTERNAL_EDITOR=jmemo

Sorry for a lengthy post.
Best regards,
Keita

brianh
10-27-2002, 08:19 AM
Hello Keita

Thanks for the source code examples. I will try using the OPL database method.

I will also look at the source code from your site.

I appreciate the help and will post if I have any further questions.

Thanks again.