cfgtest.pp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. {$MODE objfpc}
  2. {$H+}
  3. program cfgtest;
  4. uses xmlcfg;
  5. var
  6. cfg: TXMLConfig;
  7. i: Integer;
  8. s: String;
  9. b: Boolean;
  10. begin
  11. WriteLn('Writing a sample XML configuration to "testcfg.xml"...');
  12. cfg := TXMLConfig.Create(nil);
  13. cfg.Filename := 'testcfg.xml';
  14. cfg.SetValue('cfgtest/MainWindow/Constraints/Width', 600);
  15. cfg.SetValue('cfgtest/MainWindow/Constraints/Height', 400);
  16. cfg.SetValue('cfgtest/MainWindow/Caption', 'TXMLConfig Test');
  17. cfg.SetValue('cfgtest/SomeForm/Presets/Preset1/Name', 'Example');
  18. cfg.SetValue('TipOfTheDay/Disabled', True);
  19. cfg.Free;
  20. WriteLn('Ok; now I''ll try to read back all values...');
  21. cfg := TXMLConfig.Create(nil);
  22. cfg.Filename := 'testcfg.xml';
  23. i := cfg.GetValue('cfgtest/MainWindow/Constraints/Width', 0);
  24. if i <> 600 then
  25. WriteLn('Invalid value: cfgtest/MainWindow/Constraints/Width, got ', i);
  26. i := cfg.GetValue('cfgtest/MainWindow/Constraints/Height', 400);
  27. if i <> 400 then
  28. WriteLn('Invalid value: cfgtest/MainWindow/Constraints/Height, got ', i);
  29. s := cfg.GetValue('cfgtest/MainWindow/Caption', '');
  30. if s <> 'TXMLConfig Test' then
  31. WriteLn('Invalid value: cfgtest/MainWindow/Caption, got "', s, '"');
  32. s := cfg.GetValue('cfgtest/SomeForm/Presets/Preset1/Name', '');
  33. if s <> 'Example' then
  34. WriteLn('Invalid value: cfgtest/SomeForm/Presets/Preset1/Name, got "', s, '"');
  35. b := cfg.GetValue('TipOfTheDay/Disabled', False);
  36. if b <> True then
  37. WriteLn('Invalid value: TipOfTheDay/Disabled, got ', b);
  38. cfg.Free;
  39. WriteLn('Done!');
  40. end.