cfgtest.pp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // $Id$
  2. {$MODE objfpc}
  3. {$H+}
  4. program cfgtest;
  5. uses xmlcfg;
  6. var
  7. cfg: TXMLConfig;
  8. i: Integer;
  9. s: String;
  10. b: Boolean;
  11. begin
  12. WriteLn('Writing a sample XML configuration to "testcfg.xml"...');
  13. cfg := TXMLConfig.Create('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('testcfg.xml');
  22. i := cfg.GetValue('cfgtest/MainWindow/Constraints/Width', 0);
  23. if i <> 600 then
  24. WriteLn('Invalid value: cfgtest/MainWindow/Constraints/Width, got ', i);
  25. i := cfg.GetValue('cfgtest/MainWindow/Constraints/Height', 400);
  26. if i <> 400 then
  27. WriteLn('Invalid value: cfgtest/MainWindow/Constraints/Height, got ', i);
  28. s := cfg.GetValue('cfgtest/MainWindow/Caption', '');
  29. if s <> 'TXMLConfig Test' then
  30. WriteLn('Invalid value: cfgtest/MainWindow/Caption, got "', s, '"');
  31. s := cfg.GetValue('cfgtest/SomeForm/Presets/Preset1/Name', '');
  32. if s <> 'Example' then
  33. WriteLn('Invalid value: cfgtest/SomeForm/Presets/Preset1/Name, got "', s, '"');
  34. b := cfg.GetValue('TipOfTheDay/Disabled', False);
  35. if b <> True then
  36. WriteLn('Invalid value: TipOfTheDay/Disabled, got ', b);
  37. cfg.Free;
  38. WriteLn('Done!');
  39. end.
  40. {
  41. $Log$
  42. Revision 1.2 2000-07-13 11:33:03 michael
  43. + removed logs
  44. }