Re: [BLACKBOX] INI files (was: How to find out if a document is "dirty")

From: [at]} <Chris>
Date: Thu, 19 Jul 2012 08:00:15 +0930

----boundary-LibPST-iamunique-1541238765_-_-
Content-type: text/plain

> -----Original Message-----
> From: BlackBox [mailto:BLACKBOX{([at]})nowhere.xy
> Neubauer
> Sent: Wednesday, 18 July 2012 11:42 PM
> To: BLACKBOX{([at]})nowhere.xy
> Subject: Re: [BLACKBOX] How to find out if a document is "dirty"
>
....
>
> I should have mentioned perhaps that in my application the user will not
> modify source code usually found in programs.
> The application needs a bunch of parameters the user should be able to
> modify. At first I planned to put them in a configuration file like this
one:
>
> [ClimateChamber]
> Enabled=TRUE
> MinTemp=-50
...
...
> For the user this is very ugly to maintain and error prone, and for me it
means
> to develop a program which would interpret this stuff, that means, first
> checking for presence of all parameters and then checking all types and
> values. Because from time to time the number of these parameters will
> change, I would have to change my program too.
>

This is a fairly common task that justifies a standard library module. I
described an alternative approach which I use regularly in a reply to this
mailing list back in 2006. It's a good simple example of the usefulness of
Oberon's / Component Pascal's 'type extensions':

> Is there a standard way in BlackBox for keeping program's settings
> between runs?
> HostRegistry is not a good idea, because it is not portable.
> I'm talking about some sort of configuration files, like ini-files?
> Did anyone work with those? Do you have any modules of subsystems
> you could share?
>

I don't know about a standard way for BlackBox but I've done some work on
this using GPCP and have designed a system that can be interchangeable
between Ini files and Registry keys. The following snippet should give you a
feel for how it works:

VAR
  formHeight: IniFile.IntegerItem;
  formTitle: IniFile.StringItem;
  maximised: IniFile.BooleanItem;
  list: IniFile.List;
  
BEGIN
  NEW(list);
  IniFile.Init(list, 'test.ini');

  (* Associate INI file keys with program variables and default values
*)
  list.AddInteger('Form Height', formHeight, 400);
  list.AddString('Form Title', formTitle, 'Test Program');
  list.AddBoolean('Maximised', maximised, TRUE);

  (* Read the contents of the INI file and assign values to the program
variables *)
  list.Load();
...
...
...
  formHeight.value := formHeight.value + 20;
  formTitle.value := formTitle.value + ' v1.0';
  maximised.value := ~ maximised.value;

  (* Write the updated values to the INI file *)
  list.Save();

 
With the above code, if the initial IniFile, 'test.ini', had the
contents:

  Form Height = 420
  Maximised = FALSE

After executing the code the IniFile would have the contents:

  Form Height = 440
  Form Title = Test Program v1.0
  Maximised = TRUE

It shouldn't take long to port it to BlackBox - it's mainly the text file IO
that would have to be translated. Let me know if you are interested and I'll
give it a go.

Chris Burrows
CFB Software
http://www.cfbsoftware.com/gpcp


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-1541238765_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGZiaWRpcyBcZGVmZjB7XGZvbnR0YmwN
CntcZjBcZnN3aXNzIEFyaWFsO30NCntcZjFcZm1vZGVybiBDb3VyaWVyIE5ldzt9DQp7XGYyXGZu
aWxcZmNoYXJzZXQyIFN5bWJvbDt9DQp7XGYzXGZtb2Rlcm5cZmNoYXJzZXQwIENvdXJpZXIgTmV3
O319DQp7XGNvbG9ydGJsXHJlZDBcZ3JlZW4wXGJsdWUwO1xyZWQwXGdyZWVuMFxibHVlMjU1O30N
Clx1YzFccGFyZFxwbGFpblxkZWZ0YWIzNjAgXGYwXGZzMjAgPiAtLS0tLU9yaWdpbmFsIE1lc3Nh
Z2UtLS0tLVxwYXINCj4gRnJvbTogQmxhY2tCb3ggW21haWx0bzpCTEFDS0JPWEBMSVNUUy5PQkVS
T04uQ0hdIE9uIEJlaGFsZiBPZiBSYWluZXJccGFyDQo+IE5ldWJhdWVyXHBhcg0KPiBTZW50OiBX
ZWRuZXNkYXksIDE4IEp1bHkgMjAxMiAxMTo0MiBQTVxwYXINCj4gVG86IEJMQUNLQk9YQExJU1RT
Lk9CRVJPTi5DSFxwYXINCj4gU3ViamVjdDogUmU6IFtCTEFDS0JPWF0gSG93IHRvIGZpbmQgb3V0
IGlmIGEgZG9jdW1lb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zXHBhcg0KQ0ZCIFNvZnR3YXJlXHBh
cg0KaHR0cDovL3d3dy5jZmJzb2Z0d2FyZS5jb20vZ3BjcFxwYXINClxwYXINClxwYXINCi0tLS1c
cGFyDQpUbyB1bnN1YnNjcmliZSwgc2VuZCBhIG1lc3NhZ2Ugd2l0aCBib2R5ICJTSUdOT0ZGIEJM
QUNLQk9YIiB0byBMSVNUU0VSVkBMSVNUUy5PQkVST04uQ0hcfX0ALmFk
----boundary-LibPST-iamunique-1541238765_-_---
Received on Thu Jul 19 2012 - 00:30:15 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:00 UTC