diff options
| author | michael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2007-09-21 20:46:24 +0000 |
|---|---|---|
| committer | michael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2007-09-21 20:46:24 +0000 |
| commit | 957ed8c1a44f09933fc5dd3517bb8f7061100e70 (patch) | |
| tree | cc19cfdc5964697be6fea55502f0f1c3b14b03d6 /packages/fcl-json | |
| parent | e1a6078de689de81ad952baebbaf91ec8ea2a9c4 (diff) | |
| download | fpc-957ed8c1a44f09933fc5dd3517bb8f7061100e70.tar.gz | |
* Demo for TJONConfig committed, copyright notice added
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@8598 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/fcl-json')
| -rw-r--r-- | packages/fcl-json/demo/confdemo.lpi | 46 | ||||
| -rw-r--r-- | packages/fcl-json/demo/confdemo.pp | 101 | ||||
| -rw-r--r-- | packages/fcl-json/demo/parsedemo.pp | 14 | ||||
| -rw-r--r-- | packages/fcl-json/demo/simpledemo.pp | 14 |
4 files changed, 175 insertions, 0 deletions
diff --git a/packages/fcl-json/demo/confdemo.lpi b/packages/fcl-json/demo/confdemo.lpi new file mode 100644 index 0000000000..4b8500a952 --- /dev/null +++ b/packages/fcl-json/demo/confdemo.lpi @@ -0,0 +1,46 @@ +<?xml version="1.0"?> +<CONFIG> + <ProjectOptions> + <PathDelim Value="/"/> + <Version Value="5"/> + <General> + <SessionStorage Value="InProjectDir"/> + <MainUnit Value="0"/> + <TargetFileExt Value=""/> + </General> + <VersionInfo> + <ProjectVersion Value=""/> + </VersionInfo> + <PublishOptions> + <Version Value="2"/> + <IgnoreBinaries Value="False"/> + <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/> + <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> + </local> + </RunParams> + <Units Count="1"> + <Unit0> + <Filename Value="confdemo.pp"/> + <IsPartOfProject Value="True"/> + <UnitName Value="confdemo"/> + </Unit0> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="5"/> + <SearchPaths> + <OtherUnitFiles Value="../src/"/> + </SearchPaths> + <CodeGeneration> + <Generate Value="Faster"/> + </CodeGeneration> + <Other> + <CompilerPath Value="$(CompPath)"/> + </Other> + </CompilerOptions> +</CONFIG> diff --git a/packages/fcl-json/demo/confdemo.pp b/packages/fcl-json/demo/confdemo.pp new file mode 100644 index 0000000000..29d0e95c93 --- /dev/null +++ b/packages/fcl-json/demo/confdemo.pp @@ -0,0 +1,101 @@ +{ + This file is part of the Free Component Library + + JSON Config file demo + Copyright (c) 2007 by Michael Van Canneyt michael@freepascal.org + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} +program confdemo; + +{$mode objfpc}{$H+} + +uses + Classes, + { add your units here } + jsonconf; + +Procedure TestConf; + +Var + C : TJSONConfig; + L : TStrings; + I : Integer; + +begin + // TJSONConf is component, so needs an owner. + C:=TJSONConfig.Create(nil); + Try + // Set filename. This will read the file. + C.FileName:='sample.conf'; + // Set an integer value "a" equal to 1 in the root object + C.SetValue('/a',1); + // Set a integer value "a" equal to 2 in the object "b" below root. + C.SetValue('b/a',2); + // Set a string value "b" equal to 1 in the object "b" below root. + C.SetValue('b/b','Some String'); + // Set a float value "c" equal to 1.23 in the object "b" below root. + C.SetValue('b/c',1.23); + // Set a boolean value "d" equal to "False" in the object "b" below root. + C.SetValue('b/d',False); + // Read values: + // Integer. If none found, 0 is returned) + Writeln('/a :',C.GetValue('/a',0)); + // String. If none found, a default 'XYZ' is returned) + Writeln('/b/b :',C.GetValue('/b/b','XYZ')); + // Float. If none found, 0 is returned) + Writeln('/b/c :',C.GetValue('/b/c',0)); + // Boolean. If none found, true is returned) + Writeln('/b/d :',C.GetValue('/b/d',true)); + // You can open a key. All paths are then relative to the open key. + // The default open key is the root key. + // The second element determines if the key should b created if it does not exist. + C.OpenKey('/b',False); + // Read relative to b + Writeln('a, relative to key (/b):',C.GetValue('a',0)); + // Absolute paths disregard the open key + Writeln('/a, absolute:',C.GetValue('/a',0)); + // Reset or closekey reset the open key to the root key. + C.OpenKey('/b/c/d/e',True); + C.SetValue('q','Q is good for you'); + // Opening keys also works relative: + C.OpenKey('/b',False); + Writeln('a, in b : ',C.GetValue('a',0)); + C.OpenKey('c/d/e',False); + Writeln('q, in /b, then c/d/e : ',C.GetValue('q','')); + C.ResetKey; + C.OpenKey('/b2',True); + C.OpenKey('/b3',True); + L:=TStringList.Create; + try + // You can enumerate keys below a certain key: + C.EnumSubKeys('/',L); + Writeln('Found ',L.Count,' keys below root key: '); + For I:=0 to L.Count-1 do + Writeln(i+1,': ',L[I]); + // You can also enumerate the values below a certain key: + L.Clear; + C.EnumValues('/b',L); + Writeln('Found ',L.Count,' values below "/b" key: '); + For I:=0 to L.Count-1 do + Writeln(i+1,': ',L[I]); + finally + L.Free; + end; + // Write all in-memory changes to disk + C.Flush; + Finally + C.Free; + end; +end; + +begin + TestConf; +end. + diff --git a/packages/fcl-json/demo/parsedemo.pp b/packages/fcl-json/demo/parsedemo.pp index 19e389f40e..00e534b42d 100644 --- a/packages/fcl-json/demo/parsedemo.pp +++ b/packages/fcl-json/demo/parsedemo.pp @@ -1,3 +1,17 @@ +{ + This file is part of the Free Component Library + + JSON Parser demo + Copyright (c) 2007 by Michael Van Canneyt michael@freepascal.org + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} program parsedemo; {$mode objfpc}{$H+} diff --git a/packages/fcl-json/demo/simpledemo.pp b/packages/fcl-json/demo/simpledemo.pp index f0b7ebbcc1..5f53173474 100644 --- a/packages/fcl-json/demo/simpledemo.pp +++ b/packages/fcl-json/demo/simpledemo.pp @@ -1,3 +1,17 @@ +{ + This file is part of the Free Component Library + + JSON Data structures demo + Copyright (c) 2007 by Michael Van Canneyt michael@freepascal.org + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} program simpledemo; {$mode objfpc}{$H+} |
