diff --git a/Projects/settings/project1.lpi b/Projects/settings/project1.lpi
index fb5b63d..9604d45 100644
--- a/Projects/settings/project1.lpi
+++ b/Projects/settings/project1.lpi
@@ -10,7 +10,7 @@
-
+
@@ -39,7 +39,7 @@
-
+
@@ -47,10 +47,10 @@
-
-
+
+
-
+
@@ -59,8 +59,8 @@
-
-
+
+
@@ -84,10 +84,10 @@
-
-
+
+
-
+
@@ -146,124 +146,124 @@
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
-
+
+
-
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
diff --git a/Projects/settings/settings.pas b/Projects/settings/settings.pas
index d1c752b..1c1bab0 100644
--- a/Projects/settings/settings.pas
+++ b/Projects/settings/settings.pas
@@ -39,9 +39,10 @@ type
function KeyExists(KeyName: String): Boolean;
function IsKey(KeyName: String): Boolean;
function IsDirectory(KeyName: String): Boolean;
- procedure SetKey(KeyName: String; KeyValue: String);
+ procedure SetKeyValue(KeyName: String; KeyValue: String);
function CreateKey(KeyName: String; CreatePath: Boolean = False): Boolean;
function GetKeyValue(KeyName: String): String;
+ function GetSetDefaultKeyValue(KeyName, defVal: String): String;
end;
@@ -197,10 +198,7 @@ begin
while N <> nil do
begin
if N.Text <> 'Value' then
- begin
- writeln(N.text);
inc(i);
- end;
N := N.GetNextSibling;
end;
@@ -221,17 +219,40 @@ function TMMLSettings.GetKeyValue(KeyName: String): String;
var
N: TTreeNode;
begin
- if IsKey(KeyName) then
+ if not KeyExists(KeyName) then
Exit('');
N := WalkToNode(KeyName);
if N <> nil then
- if N.GetFirstChild <> nil then
- if assigned(n.GetFirstChild.Data) then
- Exit(TSettingData(n.GetFirstChild.Data).Val);
-
+ N := N.GetFirstChild;
+ while N <> nil do
+ begin
+ if N.Text = 'Value' then
+ if assigned(n.Data) then
+ Exit(TSettingData(n.Data).Val);
+ N := N.GetNextSibling;
+ end;
Exit('');
end;
+function TMMLSettings.GetSetDefaultKeyValue(KeyName, defVal: String): String;
+var
+ Res: String;
+begin
+ if not IsKey(KeyName) then
+ begin
+ CreateKey(KeyName, True);
+ SetKeyValue(KeyName, defVal);
+ exit(defVal);
+ end;
+ Res := GetKeyValue(KeyName);
+ if Res = '' then
+ begin
+ SetKeyValue(KeyName, defVal);
+ exit(defVal);
+ end;
+ Exit(Res);
+end;
+
function TMMLSettings.CreateKey(KeyName: String; CreatePath: Boolean = False): Boolean;
var
N, newN, nParent: TTreeNode;
@@ -242,7 +263,6 @@ var
begin
if KeyExists(KeyName) then
begin
- writeln('Key: ' + KeyName + ' exists');
Exit(False);
end;
NewPath := '';
@@ -305,10 +325,37 @@ begin
newN.MoveTo(nParent, naAddChild);
end;
-procedure TMMLSettings.SetKey(KeyName: String; KeyValue: String);
+procedure TMMLSettings.SetKeyValue(KeyName: String; KeyValue: String);
+var
+ N, NN: TTreeNode;
begin
- if IsKey(KeyName) then
+ if not KeyExists(KeyName) then
Exit;
+ if not IsKey(KeyName) then
+ Exit;
+
+ N := WalkToNode(KeyName);
+
+ if not N.HasChildren then
+ begin
+ NN := TTreeNode.Create(Nodes);
+ NN.Text := 'Value';
+ NN.MoveTo(N, naAddChild);
+ end;
+
+ if n <> nil then
+ N := N.GetFirstChild;
+ while N <> nil do
+ begin
+ if N.Text = 'Value' then
+ begin
+ if Assigned(N.Data) then
+ TSettingData(N.Data).Free;
+ N.Data := TSettingData.Create;
+ TSettingData(N.Data).Val := KeyValue;
+ end;
+ N := N.GetNextSibling;
+ end;
end;
end.
diff --git a/Projects/settings/unit1.pas b/Projects/settings/unit1.pas
index ffcea17..fcbe453 100644
--- a/Projects/settings/unit1.pas
+++ b/Projects/settings/unit1.pas
@@ -6,7 +6,7 @@ interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
- ComCtrls, StdCtrls, xml2, XMLRead, XMLWrite, DOM;
+ ComCtrls, StdCtrls, XMLRead, XMLWrite, DOM;
type
@@ -44,7 +44,13 @@ var
DDataNode, DataNode: TDOMNode;
begin
- XMLChild := XMLDoc.CreateElement(n.Text);
+ if n.Text = 'Value' then
+ begin
+ XMLChild := XMLDoc.CreateTextNode(TSettingData(N.Data).Val);
+ end else
+ begin
+ XMLChild := XMLDoc.CreateElement(n.Text);
+ end;
Inc(C);
XMLNode.AppendChild(XMLChild);
end;
@@ -156,19 +162,16 @@ var
begin
sett := TMMLSettings.Create(TreeView1.Items);
+ sett.CreateKey('Settings/FullScreen/wat', true);
+ sett.SetKeyValue('Settings/FullScreen/wat', 'TRUE');
+ writeln(sett.GetKeyValue('Settings/FullScreen/wat'));
- if sett.KeyExists('') then
- writeln('Tree exists');
- if sett.KeyExists('Settings/a/b/c') then
- writeln('Settings exists');
+ writeln(sett.GetSetDefaultKeyValue('Settings/FullScreen/wat2', 'OWAT'));
- {writeln(sett.GetKeyValue('Settings/hoi0/Item1/Item2/Item3/wattt')); }
- sett.CreateKey('Settings/a/b/c', true);
+ writeln(sett.GetSetDefaultKeyValue('Settings/Component1/hoiii', 'NO U'));
- if sett.iskey('Settings/a/b/c') then
- writeln('is key');
-
- s := sett.ListKeys('Settings');
+ writeln(sett.GetSetDefaultKeyValue('Settings/Component2/hoi', 'OK'));
+ s := sett.ListKeys('Settings/FullScreen');
for i := 0 to high(s) do
writeln(s[i]);