Problems reading from TXMLConfig
lazarus / 62-General
----------------------------------------------------------------------
dietmar · 2021-09-17 17:06
Hi,
I have a XML config file which looks like this:
I now try to load these options at program start:
Code: Text [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i function
GetInt(const APath: WideString; const ADefault: WideString): LongInt;
var b: Boolean; i: LongInt; begin b :=
TryStrToInt(AnsiString(frmOpt.XMLConfig.GetValue(APath,
ADefault)),i); if (not b) then flag := True; exit(i);
end;
This works for bla := GetInt('Confirmations/ExitProgram','');
I now try to load the string values with this:
Code: Text [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i function
GetString(const APath: WideString; const ADefault: WideString):
String; var s: String; begin s :=
AnsiString(frmOpt.XMLConfig.GetValue(APath, ADefault)); exit(s);
end;
This does NOT work for DbDatabaseDir :=
GetString('Database/StandardDirectory','');
(It doesn't work either when I omit the AnsiString-Cast...
The debugger says, the variable is NIL.
Any ideas?
Thx,
--Dietmar
----------------------------------------------------------------------
wp · 2021-09-17 20:07
I don't know what's wrong in your code.
The following one, based on yours, is working correctly:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i const xml
= '' + ''+
''+ ''+ ''; procedure
TForm1.Button1Click(Sender: TObject);var stream: TStringStream;begin
stream := TStringStream.Create(xml); try
XMLConfig1.LoadFromStream(stream); Label1.Caption :=
XMLConfig1.GetValue('Confirmations/ExitProgram', 0).ToString;
Label2.Caption := XMLConfig1.GetValue('Database/StandardDirectory',
''); finally stream.Free; end;end;
----------------------------------------------------------------------
dietmar · 2021-09-18 14:53
Yes, but even entries with values in it where read as empty/NIL
strings...
But I now also found my second error: The entry names in the XML file
seem to be case sensitive, and I had a little "case error" in them :/
Glad I found it, now all works.
Thanks @all!
--Dietmar