procedure JSONObjectToIniFile(aobj: ISuperObject; Filename: String);
var
IniFile: TMemIniFile;
I, II: Integer;
obj, obj2: ISuperObject;
begin
IniFile := TMemIniFile.Create(Filename);
for I := 0 to aobj.Count-1 do
begin
obj2 := aobj.O[aobj.CurrentKey];
for II := 0 to obj2.Count-1 do
begin
case obj2.CurrentValue.DataType of
TDataType.dtString:
IniFile.WriteString(aobj.CurrentKey,obj2.CurrentKey,obj2.CurrentValue.AsVariant);
TDataType.dtInteger:
IniFile.WriteInteger(aobj.CurrentKey,obj2.CurrentKey,obj2.CurrentValue.AsVariant);
TDataType.dtBoolean:
IniFile.WriteBool(aobj.CurrentKey,obj2.CurrentKey,obj2.CurrentValue.AsVariant);
TDataType.dtFloat:
IniFile.WriteFloat(aobj.CurrentKey,obj2.CurrentKey,obj2.CurrentValue.AsVariant);
else
IniFile.WriteString(aobj.CurrentKey,obj2.CurrentKey,obj2.CurrentValue.AsVariant);
end;
obj2.Next;
end;
obj2 := nil;
aobj.Next;
end;
IniFile.UpdateFile;
IniFile.Free;
end;
procedure JSONArrayToIniFile(aobj: ISuperArray; Filename: String);
var
IniFile: TMemIniFile;
I, II: Integer;
obj, obj2: ISuperObject;
begin
IniFile := TMemIniFile.Create(Filename);
for I := 0 to aobj.Length-1 do
begin
obj2 := aobj.O[I];
for II := 0 to obj2.Count-1 do
begin
case obj2.CurrentValue.DataType of
TDataType.dtString:
IniFile.WriteString(IntToStr(I),obj2.CurrentKey,obj2.CurrentValue.AsVariant);
TDataType.dtInteger:
IniFile.WriteInteger(IntToStr(I),obj2.CurrentKey,obj2.CurrentValue.AsVariant);
TDataType.dtBoolean:
IniFile.WriteBool(IntToStr(I),obj2.CurrentKey,obj2.CurrentValue.AsVariant);
TDataType.dtFloat:
IniFile.WriteFloat(IntToStr(I),obj2.CurrentKey,obj2.CurrentValue.AsVariant);
else
IniFile.WriteString(IntToStr(I),obj2.CurrentKey,obj2.CurrentValue.AsVariant);
end;
obj2.Next;
end;
obj2 := nil;
end;
IniFile.UpdateFile;
IniFile.Free;
end;
function IniFileToJSONObject(Filename: String): String;
var
IniFile: TMemIniFile;
I, II: Integer;
SL, SL2: TStringList;
aobj: ISuperObject;
obj, obj2: ISuperObject;
begin
IniFile := TMemIniFile.Create(Filename);
SL := TStringList.Create;
SL2 := TStringList.Create;
IniFile.ReadSections(SL);
aobj := SO;
for I := 0 to SL.Count-1 do
begin
SL2.Clear;
IniFile.ReadSectionValues(SL[I],SL2);
obj2 := SO;
for II := 0 to SL2.Count-1 do
begin
obj2.V[SL2.Names[II]] := SL2.ValueFromIndex[II];
end;
aobj.O[SL[I]] := obj2;
obj2 := nil;
end;
SL2.Free;
SL.Free;
IniFile.Free;
Result := aobj.AsJSON;
end;
function IniFileToJSONArray(Filename: String): String;
var
IniFile: TMemIniFile;
I, II: Integer;
SL, SL2: TStringList;
aobj: ISuperArray;
obj, obj2: ISuperObject;
begin
IniFile := TMemIniFile.Create(Filename);
SL := TStringList.Create;
SL2 := TStringList.Create;
IniFile.ReadSections(SL);
aobj := SA;
for I := 0 to SL.Count-1 do
begin
SL2.Clear;
IniFile.ReadSectionValues(SL[I],SL2);
obj2 := SO;
for II := 0 to SL2.Count-1 do
begin
obj2.V[SL2.Names[II]] := SL2.ValueFromIndex[II];
end;
aobj.Add(obj2);
obj2 := nil;
end;
SL2.Free;
SL.Free;
IniFile.Free;
Result := aobj.AsJSON;
end;
Head over and download the latest version of XSuperObject which is required to use the JSON to INI file functions.